Skip to main content
Version: 5.x

Configure Dockerfile & Context

dockerfile

The dockerfile option expects a string with a path to a Dockerfile.

  • The path in dockerfile should be relative to the devspace.yaml.
  • When setting the dockerfile option, it is often useful to set the context option as well.
  • To share your configuration with team mates, make sure devspace.yaml and all Dockerfiles used in the images section 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 ./Dockerfile and the context path ./.
  • The second image would be built using the Dockerfile in ./frontend/Dockerfile and the context path ./frontend/.
  • Switching the context for image frontend would assure that a statement like ADD file.txt or COPY file.txt . in ./frontend/Dockerfile would use the local file ./frontend/file.txt instead of ./file.txt.
  • In this example, it would probably be useful to have a ./.dockerignore file which ignores the frontend/ folder when building the first image called backend.
note

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: ./

Example

See "Example: Different Dockerfiles"