Docker Cheat Sheet

A Programming › DevOps cheat sheet in English by nirintsoa

These are the docker commands I use daily

8,738 views 1,149 downloads 20 Dec 2023 History

Creating and Starting

run
Create and run a container from an image
run --rm
Automa­tically remove the container when it exits
run -d
Run container in background and print container ID
start
Start one or more stopped containers
CTRL+P, CTRL+Q
Detach from container without killing it

compos­e.yaml

version (optional)
services (optional)
volumes
networks

compose services

image
ports
enviro­nment
networks
volumes

Monitoring

images
List local images
ps
To list currently running contai­­ners
history
Show the history of an image
inspect
Return low-level inform­ation on Docker objects
attach
Attach local standard input, output, and error streams to a running container
stop
Stop one or more running containers
logs
Fetch the logs of a container
exec
Execute a command in a running container

Compose

up
Create and start containers
up -d
Detached mode: Run containers in the background
stop
Stop services
start
Start services
logs
View output from containers
down
Stop and remove contai­ners, networks
down -v
Remove contai­ners, netwRemove named volumes declared in the "­vol­ume­s" section of the Compose file and anonymous volumes attached to contai­ner­s.orks, volumes

Networking

run -p
Publish a contai­ner­'s port(s) to the host
run --network
Connect a container to a network
network
Manage networks
network create -d
Driver to manage the Network: none, bridge, host, overlay, macvlan

Dockerfile

FROM
Create a new build stage from a base image
RUN
Execute build commands

Build image

build
Build an image from a Dockerfile
build -t
Name and optionally a tag in the name:tag format

Volumes

run -v
Bind mount a volume
volume create
Create a volume

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.