FROM - This is a mandatory beginning command for Dockerfiles. It pulls any base image and assigns an alias to it if specified. It is possible to use an ARG command prior to the first FROM. However the variable cannot be used pass the FROM. A preceding ENV would usually be used to declare a version of the image to be pulled by the FROM statement eg:
1
2
3
ARG IMG_VER=1.0.0
FROM BaseImage:${IMG_VER} as basestep
ARG IMG_VER
The second declaration of IMG_VER is because it has to be redeclared after the FROM in case the default value needs to be accessed. When redeclared with no value, it is assigned the value from the previous declation ie 1.0.0
COPY - the only commands that runs on the local machine where the docker file is being executed. All other commands eg RUN will be within the container. COPY is usually used to copy source code from the local machine to the container where the code will be built. --from switch can be used to modify the source stage of the copy instruction. The --from can be a previous build layer eg:
1
2
3
4
FROM buildtools AS build
FROM BaseImage AS basestep
COPY --from=build /app
Docker build with target switch - basically in a multistage build process, the --target switch allows to select the stage at which the image will be retrieved. All other stages beyond the target stage get ignored. This is popularly used in CI pipelines whereby the Dockerfile will have a stage for running unit tests but the a stage determining the build status will only run as far as building the solution.