\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Anders Lee (AndersLee)} \pdfinfo{ /Title (docker-29-and-docker-compose-v5-commands.pdf) /Creator (Cheatography) /Author (Anders Lee (AndersLee)) /Subject (Docker 29 and Docker Compose v5 Commands Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1D63ED} \definecolor{LightBackground}{HTML}{F0F5FD} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Docker 29 and Docker Compose v5 Commands Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Anders Lee (AndersLee)} via \textcolor{DarkBackground}{\uline{cheatography.com/219408/cs/48592/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Anders Lee (AndersLee) \\ \uline{cheatography.com/anderslee} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 13th November, 2026.\\ Updated 13th November, 2026.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Containers}} \tn % Row 0 \SetRowColor{LightBackground} docker run -d -{}-name web -p 8080:80 nginx:1.30 & Run in the background and map host port 8080 to container port 80 \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} docker run -it -{}-rm ubuntu:26.04 bash & Interactive shell; container is removed when it exits \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} docker ps & List running containers \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} docker ps -a & List all containers, including stopped ones \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} docker stop web / docker start web & Stop / start a container \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} docker restart web & Restart a container \tn % Row Count 15 (+ 1) % Row 6 \SetRowColor{LightBackground} docker rm web & Remove a stopped container \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} docker rm -f web & Force-remove a running container \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} docker logs -f web & Follow a container's logs \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} docker logs -{}-tail 100 web & Show only the last 100 log lines \tn % Row Count 23 (+ 2) % Row 10 \SetRowColor{LightBackground} docker exec -it web sh & Open a shell inside a running container \tn % Row Count 25 (+ 2) % Row 11 \SetRowColor{white} docker cp web:/path/file . & Copy a file from the container to the host \tn % Row Count 28 (+ 3) % Row 12 \SetRowColor{LightBackground} docker inspect web & Full container details as JSON \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Containers (cont)}} \tn % Row 13 \SetRowColor{LightBackground} docker stats & Live CPU / memory / network usage \tn % Row Count 2 (+ 2) % Row 14 \SetRowColor{white} docker top web & Processes running inside the container \tn % Row Count 4 (+ 2) % Row 15 \SetRowColor{LightBackground} docker port web & Show port mappings \tn % Row Count 5 (+ 1) % Row 16 \SetRowColor{white} docker update -{}-restart unless-stopped web & Change the restart policy of an existing container \tn % Row Count 8 (+ 3) % Row 17 \SetRowColor{LightBackground} docker run -{}-init ... & Small init as PID 1, so stop signals are forwarded (no 10 s wait on docker stop) \tn % Row Count 12 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Names like web are examples; any container name or ID works.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Images}} \tn % Row 0 \SetRowColor{LightBackground} docker images & List local images \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker images -{}-tree & Show the platforms inside multi-platform images \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} docker pull nginx:1.30 & Pull an image \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker tag myapp user/myapp:1.0 & Add a new name or tag \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} docker push user/myapp:1.0 & Push to a registry \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} docker rmi nginx:1.30 & Remove an image \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} docker history nginx:1.30 & Show image layers \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} docker buildx imagetools inspect nginx:1.30-alpine & Platforms of a remote image, without pulling it \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} docker save -o img.tar myapp & Export an image to a file \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} docker load -i img.tar & Load an image from a file \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} docker login / docker logout & Log in to / out of a registry \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Builds}} \tn % Row 0 \SetRowColor{LightBackground} docker build -t myapp . & Build with the Dockerfile in the current directory \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker build -f Dockerfile.prod -t myapp . & Use a different Dockerfile \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} docker build -{}-no-cache -t myapp . & Build without the cache \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} docker build -{}-pull -t myapp . & Pull the base image again \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} docker build -{}-target dev -t myapp:dev . & Build only up to one stage of a multi-stage file \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} docker build -{}-build-arg VERSION=1.2 . & Pass a build argument (never for passwords: it stays in the image history) \tn % Row Count 17 (+ 4) % Row 6 \SetRowColor{LightBackground} docker build -{}-secret id=token,env=TOKEN . & Pass a secret without leaving it in the image \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} docker build -{}-progress plain . & Show the full build output \tn % Row Count 22 (+ 2) % Row 8 \SetRowColor{LightBackground} docker buildx build -{}-platform linux/amd64,linux/arm64 -t user/app -{}-push . & Build for two platforms and push \tn % Row Count 26 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Volumes}} \tn % Row 0 \SetRowColor{LightBackground} docker volume create data & Create a named volume \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker volume ls & List volumes \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} docker volume inspect data & Volume details (mount point on the host) \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker volume rm data & Remove a volume \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} docker run -v data:/app/data myapp & Mount a named volume \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} docker run -v "\$(pwd):/app" myapp & Bind-mount the current directory \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Networks}} \tn % Row 0 \SetRowColor{LightBackground} docker network create appnet & Create a user-defined network (containers reach each other by name) \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} docker network ls & List networks \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} docker network inspect appnet & Show the containers on a network \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} docker run -{}-network appnet -{}-name db postgres:18 & Start a container on a network \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} docker network connect appnet web & Attach a running container to a network \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} docker network rm appnet & Remove a network \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Common run options}} \tn % Row 0 \SetRowColor{LightBackground} -d & Run in the background \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} -it & Interactive mode + terminal \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} -p host:container & Port mapping \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} -v \seqsplit{source:container-path} & Mount a volume or directory \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} -e KEY=VALUE & Environment variable \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} -{}-name & Container name \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} -{}-rm & Remove automatically when it exits \tn % Row Count 11 (+ 2) % Row 7 \SetRowColor{white} -{}-network & Network to join \tn % Row Count 12 (+ 1) % Row 8 \SetRowColor{LightBackground} -{}-restart & Restart policy (no, on-failure, always, unless-stopped) \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Docker Compose (v5)}} \tn % Row 0 \SetRowColor{LightBackground} docker compose up -d & Start all services in the background \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker compose up -d -{}-build & Rebuild images, then start \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker compose up -d -{}-wait & Return only when all services are healthy \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker compose up -d app & Recreate / rebuild only one service \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} docker compose down & Stop and remove containers and networks \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} docker compose down -v & ... and the volumes too (deletes data) \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} docker compose ps & Service status \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} docker compose logs -f app & Follow one service's logs \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} docker compose exec app sh & Shell in a running service container \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} docker compose run -{}-rm app npm test & Run a one-off command \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} docker compose pull & Pull the latest images \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} docker compose restart app & Restart a service (does NOT apply a changed compose file: use up -d) \tn % Row Count 25 (+ 4) % Row 12 \SetRowColor{LightBackground} docker compose watch & Sync or rebuild when files change (development) \tn % Row Count 28 (+ 3) % Row 13 \SetRowColor{white} docker compose -{}-profile tools up -d & Also start services in a profile \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Docker Compose (v5) (cont)}} \tn % Row 14 \SetRowColor{LightBackground} docker compose config & Print the final merged configuration \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Cleanup and disk usage}} \tn % Row 0 \SetRowColor{LightBackground} docker system df & Disk usage by images, containers, volumes, cache \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker container prune & Remove stopped containers \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} docker image prune -a & Remove all unused images \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} docker builder prune & Clear the build cache \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} docker builder prune -{}-filter until=168h & Clear only cache unused for 7+ days \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} docker volume prune & Remove unused anonymous volumes \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} docker volume prune -a & Remove ALL unused volumes, including named database volumes \tn % Row Count 16 (+ 3) % Row 7 \SetRowColor{white} docker system prune & General cleanup (volumes not included) \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} docker system prune -{}-volumes & Also anonymous volumes (named ones are kept since Docker 23) \tn % Row Count 21 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.4931 cm} x{3.4839 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{System information}} \tn % Row 0 \SetRowColor{LightBackground} docker version & Client and server versions \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker info & Engine configuration and storage details \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker events & Live event stream \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker context ls & Docker endpoints you can switch between \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Pitfalls found while testing}} \tn % Row 0 \SetRowColor{LightBackground} docker stop takes 10 seconds & The program is PID 1 and ignores SIGTERM: handle it, or run with -{}-init \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} postgres:18 exits right after start & Version 18 mounts /var/lib/postgresql, not \seqsplit{/var/lib/postgresql/data} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} Database healthy before it is ready & Add -h 127.0.0.1 to pg\_isready / mysqladmin ping \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} Redis healthcheck passes with a wrong password & redis-cli ping exits 0 on auth errors; add | grep -q PONG \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} Changing \seqsplit{MYSQL\_ROOT\_PASSWORD} has no effect & Used only on the first initialisation of the data volume \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} Edited a bind-mounted file, container sees the old one & Editors replace the file; mount the directory instead, or restart \tn % Row Count 21 (+ 4) % Row 6 \SetRowColor{LightBackground} -{}-env-file values include quotes & docker run -{}-env-file keeps quotes; Compose env\_file strips them \tn % Row Count 25 (+ 4) % Row 7 \SetRowColor{white} Secret deleted with rm is still in the image & Every layer keeps it; ARG and ENV are visible too: use -{}-secret \tn % Row Count 29 (+ 4) % Row 8 \SetRowColor{LightBackground} exec format error & CPU architecture mismatch: use -{}-platform or build multi-platform \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Pitfalls found while testing (cont)}} \tn % Row 9 \SetRowColor{LightBackground} Container named web resolves to 127.0.0.53 & .web is a real top-level domain; pick another name \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Source and longer explanations}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Every command above was run on Docker Engine 29.9, Docker Compose v5.6 and Buildx v0.38 while writing a free Docker tutorial. Each one is explained there with its real output: \seqsplit{https://codingkit.com/docker/cheatsheet/}% Row Count 5 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}