Docker Compose
Learn how to use Docker Compose to define and run multi-container Docker applications. This tutorial demonstrates setting up InfluxDB and Grafana containers with automatic startup.
Mark
Performance Testing Expert
Docker Compose is a tool for defining and running multi-container Docker applications. It leverages YAML configuration files to specify application services, allowing developers to launch all configured services with a single command.
Purpose
This tutorial demonstrates creating and operating both InfluxDB and Grafana containers simultaneously, with Grafana linked to InfluxDB and both configured for automatic startup.
Prerequisites
- Linux OS (Debian demonstrated in this example)
- Docker engine installed
Installation Steps
Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Make executable:
sudo chmod +x /usr/local/bin/docker-compose
Configuration File
Create a file called docker-compose.yml:
influxdb:
image: influxdb
container_name: influxdb
ports:
- "8086:8086"
- "8083:8083"
- "8090:8090"
restart: unless-stopped
volumes:
- /srv/docker/influxdb/data:/var/lib/influxdb
grafana:
image: grafana/grafana
container_name: grafana
ports:
- "3000:3000"
restart: unless-stopped
user: "0"
links:
- influxdb
volumes:
- /srv/docker/grafana/data:/var/lib/grafana
Execution
Launch services as a daemon:
docker-compose up -d
This command will start both containers in the background. The restart: unless-stopped configuration ensures they will automatically restart after a system reboot.
Further Reading
Tags: