docker-compose.yml Configuration

The configuration of the development environment centers around the docker-compose.yml file. Below are the specific sections and their configurations:

version: "3.7"

services:
  docs:
    build:
      context: .
      dockerfile: Dockerfile
      target: dev
    ports:
      - 8000:8000
    volumes:
      - ./:/app

Version

version: "3.7"

Defines the version of the Docker Compose file format. Ensure this is compatible with your Docker Engine.

Services

The services section is where the application components are defined. In this case, the service defined is docs.

Build Configuration

build:
  context: .
  dockerfile: Dockerfile
  target: dev
  • context: Specifies the build context where Docker looks for the Dockerfile and other required files. Using . means the current directory.

  • dockerfile: Path to the Dockerfile used to build the image.

  • target: Allows for multi-stage builds in Docker, letting you specify which stage of the Dockerfile to build. Here, dev refers to the target stage for development.

Ports

ports:
  - 8000:8000

This maps port 8000 on the host to port 8000 in the container. This means that when accessing localhost:8000, it directs traffic to the application running within the Docker container on the same port.

Volumes

volumes:
  - ./:/app

The volumes section is crucial for development. It mounts the current directory (./) to the /app directory within the container. This allows for real-time code updates, where changes made in the local directory are instantly reflected in the running application inside the container.

Summary of Configuration Options

  • Ensure that the version field is set to the correct version compatible with your setup.

  • Adjust the context, dockerfile, and target based on the specific needs of your application and Docker setup.

  • The ports mapping helps you to expose your application to the host machine and test it in your local environment.

  • The volumes configuration provides a development-friendly setup, enhancing the workflow by allowing for automatic code synchronization with the container.

Source: docker/getting-started