Sobes.tech
Junior — Middle

What information should be contained in the docker-compose.yml file for the correct operation of containers?

sobes.tech AI

Answer from AI

The docker-compose.yml file should contain the following main information for correct container operation:

  • services: description of each service (container), including image or build, startup commands, environment variables.
  • volumes: if you need to mount volumes for data storage or file sharing.
  • networks: network configuration for container interaction.
  • depends_on: dependencies between services to set startup order.

Example of a minimal docker-compose.yml:

version: '3'
services:
  web:
    image: myapp:latest
    ports:
      - "8000:8000"
    environment:
      - DEBUG=1
    volumes:
      - ./app:/app
    depends_on:
      - db
  db:
    image: postgres:13
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data: