Configure Dockerfile & Context
dockerfile
The dockerfile option expects a string with a path to a Dockerfile.
- The path in
dockerfileshould be relative to thedevspace.yaml. - When setting the
dockerfileoption, it is often useful to set thecontextoption as well. - To share your configuration with team mates, make sure
devspace.yamland allDockerfilesused in theimagessection are checked into your code repository.
Default Value For dockerfile
dockerfile: ./Dockerfile
Example: Different Dockerfile
images:
backend:
image: john/appbackend
frontend:
image: john/appfrontend
dockerfile: frontend/Dockerfile
context: frontend/
Explanation:
- 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./frontend/. - Switching the
contextfor imagefrontendwould assure that a statement likeADD file.txtorCOPY file.txt .in./frontend/Dockerfilewould use the local file./frontend/file.txtinstead of./file.txt. - In this example, it would probably be useful to have a
./.dockerignorefile which ignores thefrontend/folder when building the first image calledbackend.
See Best Practices for Image Building for details on how to optimize your Dockerfiles and use .dockerignore for faster image building.
context
The 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.
Default Value For context
context: ./