Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| engineering:computer_science:docker:docker_cheatsheet [2024/08/16 13:56] – ↷ Page moved from refractor_computer_science:docker:docker_cheatsheet to engineering:computer_science:docker:docker_cheatsheet carlossousa | engineering:computer_science:docker:docker_cheatsheet [2024/08/16 14:58] (current) – carlossousa | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== docker & docker-compose - Cheatsheet ====== | ====== docker & docker-compose - Cheatsheet ====== | ||
| + | |||
| + | **Tags:** #docker # | ||
| + | |||
| + | **Last Reviewed:** 16/08/2024 | ||
| Usefull commands for docker and docker-compose | Usefull commands for docker and docker-compose | ||
| + | |||
| + | ===== Quick Reference ===== | ||
| ^Command^Purpose| | ^Command^Purpose| | ||
| Line 20: | Line 26: | ||
| </ | </ | ||
| + | |||
| + | ===== Cheatsheet | ||
| + | |||
| + | ==== Commands ==== | ||
| + | < | ||
| + | |||
| + | docker compose version | ||
| + | docker compose config | ||
| + | docker compose start | ||
| + | docker compose stop | ||
| + | docker compose restart | ||
| + | docker compose run | ||
| + | docker compose create | ||
| + | docker compose attach | ||
| + | docker compose pause | ||
| + | docker compose unpause | ||
| + | docker compose wait | ||
| + | docker compose up | ||
| + | docker compose down | ||
| + | docker compose ps | ||
| + | docker compose top | ||
| + | docker compose events | ||
| + | docker compose logs | ||
| + | docker compose images | ||
| + | docker compose build | ||
| + | docker compose push | ||
| + | docker compose cp | ||
| + | docker compose exec | ||
| + | |||
| + | </ | ||
| + | ==== Building ==== | ||
| + | |||
| + | < | ||
| + | web: | ||
| + | # build from Dockerfile | ||
| + | build: . | ||
| + | args: # Add build arguments | ||
| + | APP_HOME: app | ||
| + | # build from custom Dockerfile | ||
| + | build: | ||
| + | context: ./dir | ||
| + | dockerfile: Dockerfile.dev | ||
| + | # build from image | ||
| + | image: ubuntu | ||
| + | image: ubuntu: | ||
| + | image: tutum/ | ||
| + | image: example-registry: | ||
| + | image: a4bc65fd | ||
| + | |||
| + | </ | ||
| + | ==== Ports ==== | ||
| + | |||
| + | < | ||
| + | ports: | ||
| + | - " | ||
| + | - " | ||
| + | # expose ports to linked services (not to host) | ||
| + | expose: [" | ||
| + | |||
| + | </ | ||
| + | ==== Environment Variables ==== | ||
| + | |||
| + | < | ||
| + | # environment vars | ||
| + | environment: | ||
| + | RACK_ENV: development | ||
| + | environment: | ||
| + | - RACK_ENV=development | ||
| + | # environment vars from file | ||
| + | env_file: .env | ||
| + | env_file: [.env, .development.env] | ||
| + | |||
| + | </ | ||
| + | ==== Dependencies ==== | ||
| + | |||
| + | < | ||
| + | # 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 | ||
| + | # make sure `db` is healthy before starting | ||
| + | # and db-init completed without failure | ||
| + | depends_on: | ||
| + | db: | ||
| + | condition: service_healthy | ||
| + | db-init: | ||
| + | condition: service_completed_successfully | ||
| + | |||
| + | </ | ||
| + | ==== Other Options ==== | ||
| + | |||
| + | < | ||
| + | # make this service extend another | ||
| + | extends: | ||
| + | file: common.yml | ||
| + | service: webapp | ||
| + | volumes: | ||
| + | - / | ||
| + | - ./ | ||
| + | # automatically restart container | ||
| + | restart: unless-stopped | ||
| + | # always, on-failure, no (default) | ||
| + | |||
| + | </ | ||
| + | ===== Advanced Features ===== | ||
| + | |||
| + | ==== Labels ==== | ||
| + | |||
| + | < | ||
| + | services: | ||
| + | web: | ||
| + | labels: | ||
| + | com.example.description: | ||
| + | |||
| + | </ | ||
| + | ==== DNS Servers ==== | ||
| + | |||
| + | < | ||
| + | services: | ||
| + | web: | ||
| + | dns: 8.8.8.8 | ||
| + | dns: | ||
| + | - 8.8.8.8 | ||
| + | - 8.8.4.4 | ||
| + | |||
| + | </ | ||
| + | ==== Devices ==== | ||
| + | |||
| + | < | ||
| + | services: | ||
| + | web: | ||
| + | devices: | ||
| + | - "/ | ||
| + | |||
| + | </ | ||
| + | ==== Healthcheck ==== | ||
| + | |||
| + | < | ||
| + | # declare service healthy when `test` command succeeds | ||
| + | healthcheck: | ||
| + | test: [" | ||
| + | interval: 1m30s | ||
| + | timeout: 10s | ||
| + | retries: 3 | ||
| + | start_period: | ||
| + | |||
| + | </ | ||
| + | ==== User ==== | ||
| + | |||
| + | < | ||
| + | # specifying user | ||
| + | user: root | ||
| + | # specifying both user and group with ids | ||
| + | user: 0:0 | ||
| + | |||
| + | </ | ||
| + | |||