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).
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).
From the official documentation we know that:
context defines either a path to a directory containing a Dockerfile, or a URL to a git repository.
In your case, . is a relative path representing the current directory where you run docker-compose command and where Compose can find a Dockerfile (and obviously also the docker-compose.yaml file).
The Dockerfile can also be elsewhere using the dockerfile keyword like that in this example:
version: "3.3"
services:
service-A
build:
context: ./all-service
dockerfile: ./service-A/Dockerfile
service-B
build:
context: ./all-service
dockerfile: ./service-B/Dockerfile
service-C
build:
context: ./all-service
dockerfile: ./service-C/Dockerfile
The additional context keyword here is to tell the Dockerfile where to find its dependent files.
For instance, in one of your Dockerfile there are these lines:
WORKDIR /my-app
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
These three files must be in the context directory or git repository: package.json, package-lock.json, requirements.txt.