What is context: . in docker-compose?
Jan 8
I am trying to learn Docker and created my first Docker compose file. Basically, I am trying to create a Django web microservice and use docker compose file to manage it. Here is my code for my docker-compose.yml:
version: "3"
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "py manage.py runserver 0.0.0.0:8000"
I don't understand the use of context: . Can someone please explain me this
1 answer
Accepted answer · original discussion
Jan 8
CONTEXT
Either a path to a directory containing a Dockerfile, or a url to a git repository.
When the value supplied is a relative path, it is interpreted as relative to the location of the Compose file. This directory is also the build context that is sent to the Docker daemon.
Compose builds and tags it with a generated name, and uses that image thereafter.
build:
context: ./dir
That mean, its a path to the directory that contains Dockerfile file. It purposes to build a new image for the service.
Reference: https://docs.docker.com/compose/compose-file/compose-file-v3/
In your case:
context: .
Dockerfile file should be existing in the current directory (in the same folder of the docker-compose.yml file).
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.