Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yamiacat/61f0e691e818cfcfa25224834778cdcd to your computer and use it in GitHub Desktop.
Save yamiacat/61f0e691e818cfcfa25224834778cdcd to your computer and use it in GitHub Desktop.
docker-compose cheat sheet
#=====================================================================
docker-compose -f docker-compose.json up #use JSON instead of YAML compose file
#=====================================================================
docker-compose -f ~/hello_world/docker-compose.yml build
docker-compose -f ~/hello_world/docker-compose.yml up -d
docker-compose ps # Lists containers.
docker-compose stop
docker-compose start # Starts existing containers for a service.
docker-compose stop # Stops running containers without removing them.
docker-compose pause # Pauses running containers of a service.
docker-compose unpause # Unpauses paused containers of a service
docker-compose up # Builds, (re)creates, starts, and attaches to containers for a service
docker-compose down # Stops containers and removes containers, networks, volumes, and images created by up.
#=====================================================================
cat Dockerfile.test
cat docker-compose.test.yml
docker-compose -f ~/hello_world/docker-compose.test.yml -p ci build
docker-compose -f ~/hello_world/docker-compose.test.yml -p ci up -d
ocker-compose -p ci stop
#=====================================================================
Docker Compose v2 Docker compose v3
Multi-host No Yes
Start services docker-compose up -d docker stack deploy --compose-file=docker-compose.yml
Scale service docker-compose scale = docker service scale =
Shutdown docker-compose down docker stack rm
#=====================================================================
# docker-compose.yml
version: '3'
services:
web:
build: .
# build from Dockerfile
context: ./Path
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: redis
#=====================================================================
# Builds, (re)creates, starts, and attaches to containers for a service.
docker-compose up
# Stops containers and removes containers, networks, volumes, and images created by up.
docker-compose down
#=====================================================================
web:
# build from Dockerfile
build: .
#=====================================================================
# build from custom Dockerfile
build:
context: ./dir
dockerfile: Dockerfile.dev
#=====================================================================
# build from image
image: ubuntu
#=====================================================================
ports:
- "3000"
- "8000:80" # guest:host
#=====================================================================
# expose ports to linked services (not to host)
expose: ["3000"]
#=====================================================================
# command to execute
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]
#=====================================================================
# override the entrypoint
entrypoint: /app/start.sh
entrypoint: [php, -d, vendor/bin/phpunit]
#=====================================================================
volumes:
- /var/lib/mysql
- ./_data:/var/lib/mysql
#=====================================================================
# join a pre-existing network
networks:
default:
external:
name: frontend
#=====================================================================
# creates a custom network called `frontend`
networks:
frontend:
#=====================================================================
# makes the `db` service available as the hostname `database`
# (implies depends_on)
links:
- db:database
- redis
#=====================================================================
# make sure `db` is alive before starting
depends_on:
- db
#=====================================================================
services:
web:
dns: 8.8.8.8
dns:
- 8.8.8.8
- 8.8.4.4
#=====================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment