Skip to content

Instantly share code, notes, and snippets.

@essic
Forked from dariahervieux/docker-cheat-sheet.md
Created May 16, 2023 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save essic/f3c6f4e3122ee165fcb5572db5f5799b to your computer and use it in GitHub Desktop.
Save essic/f3c6f4e3122ee165fcb5572db5f5799b to your computer and use it in GitHub Desktop.
Docker cheat/tip sheet

Running container

Inspect

Using inspect command:

> docker inspect <container name|ID>

Searching for a particular section, using jq utility, for example docker volumes of the container:

> docker inspect container_name_or_id | jq -r '.[0]["Config"]["Volumes"]'

Searching for a particular section using --format, -f option:

> docker inspect -f '{{.Config.Volumes}}' container_name_or_id

Regenerate the run command of the container using inspect

Using the template:

> docker inspect \
  --format "$(curl -s https://gist.githubusercontent.com/efrecon/8ce9c75d518b6eb863f667442d7bc679/raw/run.tpl)" \
  name_or_id_of_running_container

Print the IP adress of the docker container

> docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

Run a command inside a container

Starting a shell in interactive mode

> docker exec -it running_container_name_or_id bash

Files

Copy files from/to host

Copy files from container to the host:

> docker cp <conainer name|ID>:<file path inside the conainer> <file path on the host>

Volulmes

Manage volumes

List volumes: > docker volume ls

Delete unused volumes: > docker volume prune

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment