Docker Compose Common Examples

MySQL

networks:
mysql:
external: false
name: mysql_net
services:
mysql:
container_name: local_mysql
image: mysql:8.0
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- mysql
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql

PostgreSQL

networks:
postgres_net:
external: false
name: postgres_net
services:
postgres_db:
image: postgres:13
restart: always
container_name: postgres
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=
- POSTGRES_DB=
networks:
- postgres_net
ports:
- "5432:5432"
volumes:
- ./postgres:/var/lib/postgresql/data

Redis

services:
redis:
image: redis:latest
ports:
- "6379:6379"
volumes:
- ./redis:/data
command: redis-server --appendonly yes --requirepass root