Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is context: . in docker-compose?

I am trying 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

like image 520
Aryan Pandhare Avatar asked Jan 08 '21 02:01

Aryan Pandhare


People also ask

What is docker context used for?

The docker context command makes it easy to export and import contexts on different machines with the Docker client installed. You can use the docker context export command to export an existing context to a file. This file can later be imported on another machine that has the docker client installed.

Where is the docker build context?

The build context is the set of files located at the specified PATH or URL. Those files are sent to the Docker daemon during the build so it can use them in the filesystem of the image.

What is the format of Docker compose file?

The Compose file is a YAML file defining services, networks and volumes. The default path for a Compose file is ./docker-compose.yml . Tip: You can use either a .yml or .yaml extension for this file. They both work.

What is entrypoint Docker compose?

In Dockerfiles, an ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated.


Video Answer


1 Answers

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).

like image 128
Thanh Nguyen Van Avatar answered Oct 23 '22 02:10

Thanh Nguyen Van