Sobes.tech
Junior — Middle

Can you explain what Docker Compose is and how it is used to manage multiple containers?

sobes.tech AI

Answer from AI

Docker Compose is a tool for defining and running multi-container Docker applications. With the docker-compose.yml file, you can describe multiple services (containers), their images, networks, volumes, and dependencies.

This is convenient when an application consists of several components, such as a web server, a database, and a cache. Instead of starting each container manually, you describe them in a single file and manage the entire set with the command docker-compose up.

Example of a simple docker-compose.yml:

version: '3'
services:
  web:
    image: my-web-app
    ports:
      - "80:80"
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: example

Here, two services are defined: web and db. When you run Compose, it will create and start both containers, set up the network between them, and forward the ports.