Thuta Learning
Docker
AdvancedDevOps & ToolsIntermediate

docker-compose.yml

DockerLesson 15

docker-compose.yml is a YAML-format configuration file. It lets you write out the services, images, ports, volumes, and environment variables your app needs in a readable way.

dockerfile
# Create a file named docker-compose.yml
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  redis:
    image: redis:alpine
    volumes:
      - redis-data:/data

volumes:
  redis-data:

web service runs Nginx and maps it to host port 8080. The redis service runs a Redis cache and stores its data in the redis-data volume.

You should see
This file defines a stack with two services: a web server and Redis.

Info

Docker creates a Compose network by default, so services can reach each other by service name. For example, from inside the web app, you can connect to Redis at redis:6379.

Easy traps

  • Don't use tabs in YAML — stick to space indentation. Small mistakes with colons, dashes, or quotes can easily trigger Compose errors.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

docker-compose.yml | Thuta Learning