Skip to content

Instantly share code, notes, and snippets.

@jackyscript
Last active June 7, 2024 10:00
Show Gist options
  • Save jackyscript/267c7fadfdf757578a59d3ad4a93f52e to your computer and use it in GitHub Desktop.
Save jackyscript/267c7fadfdf757578a59d3ad4a93f52e to your computer and use it in GitHub Desktop.
Docker Cheatsheet

Docker Cheatsheet

Basics

Show all containers:

docker ps -a

Restart all containers (quietly):

docker restart $(docker ps -a -q)

Restart policies

docker update --restart unless-stopped $(docker ps -q)

Check restart-policy of a given container: docker inspect -f "{{ .HostConfig.RestartPolicy }}" some_container

Create docker image locally

On source machine

docker build . -t org/webdav:1.0.0

docker save org/webdav -o org_webdav.tar

On target machine

docker image load --input org_webdav.tar

docker compose file from running containers

Generate a (verbose) docker compose file from running containers using docker autocompose. Useful for deducing the current infrastructure to code. Prints out docker-compose.yml into the terminal.

Prerequisites

docker pull ghcr.io/red5d/docker-autocompose:latest

Usage

  • Example container "my_nginx"

`docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose my_nginx

Start containers using docker compose

(Abort the process if at least one container did not start successfully):

docker compose up --abort-on-container-exit

Check docker compose file:

docker compose config --quiet

Do a dry run:

docker compose --dry-run up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment