dockerfile option expects a string with a path to a
- The path in
dockerfileshould be relative to the
- When setting the
dockerfileoption, it is often useful to set the
contextoption as well.
- To share your configuration with team mates, make sure
Dockerfilesused in the
imagessection are checked into your code repository.
Default Value For
Example: Different Dockerfile
- The first image would be built using the Dockerfile in
./Dockerfileand the context path
- The second image would be built using the Dockerfile in
./frontend/Dockerfileand the context path
- Switching the
frontendwould assure that a statement like
COPY file.txt .in
./frontend/Dockerfilewould use the local file
- In this example, it would probably be useful to have a
./.dockerignorefile which ignores the
frontend/folder when building the first image called
See Best Practices for Image Building for details on how to optimize your Dockerfiles and use
.dockerignore for faster image building.
context option expects a string with a path to the folder used as context path when building the image. The context path serves as root directory for Dockerfile statements like ADD or COPY.
What does "context" mean in terms of image building?
The context is archived and sent to the Docker daemon before starting to process the Dockerfile. All references of local files within the Dockerfile are relative to the root directory of the context.
That means that a Dockerfile statement such as
COPY ./src /app would copy the folder
src/ within the context path into the path
/app within the container image. So, if the context would be
/my/project/database, for example, the folder that would be copied into
/app would have the absolute path
/my/project/database/src on your local computer.