Sobes.tech
Junior — Middle

Have you used a docker-compose.yml file in your projects for setting up and running containers?

sobes.tech AI

Answer from AI

Yes, I have used the docker-compose.yml file to simplify the setup and launch of multiple containers in projects. This is especially convenient when the application consists of several services, such as a web server, database, and cache.

In docker-compose.yml, you can describe the configuration of each service, network settings, data storage volumes, and environment variables.

An example of a simple docker-compose.yml for FastAPI with PostgreSQL:

version: '3.8'
services:
  web:
    build: .
    ports:
      - "8000:8000"
    depends_on:
      - db
    environment:
      - DATABASE_URL=postgresql://user:password@db:5432/mydb
  db:
    image: postgres:13
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: mydb
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

This allows you to run the entire infrastructure with a single docker-compose up command and makes the application more portable and scalable.