engineering:computer_science:docker:docker_cheatsheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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 carlossousaengineering: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 #dockercompose #cheatsheet
 +
 +**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:
  
 </code>       |Delete dangling images and / or images that have a "none" tag. \\ Might be helpful if "docker image prune" doesn't remove those.| </code>       |Delete dangling images and / or images that have a "none" tag. \\ Might be helpful if "docker image prune" doesn't remove those.|
 +
 +===== Cheatsheet  =====
 +
 +==== Commands ====
 +<code>
 +
 +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
 +
 +</code>
 +==== Building ====
 +
 +<code>
 +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:14.04
 +  image: tutum/influxdb
 +  image: example-registry:4000/postgresql
 +  image: a4bc65fd
 +
 +</code>
 +==== Ports ====
 +
 +<code>
 +ports:
 +  - "3000"
 +  - "8000:80"  # host:container
 +# expose ports to linked services (not to host)
 +expose: ["3000"]
 +
 +</code>
 +==== Environment Variables ====
 +
 +<code>
 +# environment vars
 +environment:
 +  RACK_ENV: development
 +environment:
 +  - RACK_ENV=development
 +# environment vars from file
 +env_file: .env
 +env_file: [.env, .development.env]
 +
 +</code>
 +==== Dependencies ====
 +
 +<code>
 +# 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
 +
 +</code>
 +==== Other Options ====
 +
 +<code>
 +# make this service extend another
 +extends:
 +  file: common.yml  # optional
 +  service: webapp
 +volumes:
 +  - /var/lib/mysql
 +  - ./_data:/var/lib/mysql
 +# automatically restart container
 +restart: unless-stopped
 +# always, on-failure, no (default)
 +
 +</code>
 +===== Advanced Features =====
 +
 +==== Labels ====
 +
 +<code>
 +services:
 +  web:
 +    labels:
 +      com.example.description: "Accounting web app"
 +
 +</code>
 +==== DNS Servers ====
 +
 +<code>
 +services:
 +  web:
 +    dns: 8.8.8.8
 +    dns:
 +      - 8.8.8.8
 +      - 8.8.4.4
 +
 +</code>
 +==== Devices ====
 +
 +<code>
 +services:
 +  web:
 +    devices:
 +    - "/dev/ttyUSB0:/dev/ttyUSB0"
 +
 +</code>
 +==== Healthcheck ====
 +
 +<code>
 +# declare service healthy when `test` command succeeds
 +healthcheck:
 +  test: ["CMD", "curl", "-f", "http://localhost"]
 +  interval: 1m30s
 +  timeout: 10s
 +  retries: 3
 +  start_period: 40s
 +
 +</code>
 +==== User ====
 +
 +<code>
 +# specifying user
 +user: root
 +# specifying both user and group with ids
 +user: 0:0
 +
 +</code>
 +
  
  
  • engineering/computer_science/docker/docker_cheatsheet.1723809387.txt.gz
  • Last modified: 2024/08/16 13:56
  • by carlossousa