\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{pratikshahp} \pdfinfo{ /Title (docker.pdf) /Creator (Cheatography) /Author (pratikshahp) /Subject (Docker 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}{797FB5} \definecolor{LightBackground}{HTML}{F6F7FA} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{pratikshahp} via \textcolor{DarkBackground}{\uline{cheatography.com/180680/cs/37579/}}} \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}pratikshahp \\ \uline{cheatography.com/pratikshahp} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 10th March, 2023.\\ Updated 20th March, 2023.\\ 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*}{2} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Installation}} \tn % Row 0 \SetRowColor{LightBackground} apt update & Updates the package sources with the latest versions \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} apt install docker.io -y & Install docker in Ubutu Linux distribution \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} systemctl start docker & Stop docker services \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} systemctl stop docker & Stop docker services \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} systemctl restart docker & Stop and start docker services \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} systemctl status docker & Check the status of docker services \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Container Operations}} \tn % Row 0 \SetRowColor{LightBackground} docker container create -{}-name web -it alpine sh & Create a named container \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker container start web & Start a container \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} docker container stop web & Stop a container \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} docker container restart web & stop and start a container \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} docker container run -it -{}-name myweb alpine sh & create and start a named container \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} Ctrl + p, Ctrl + q & Detach from the container \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} docker container attach myweb & Attach to a running container \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} docker container logs myweb & See the logs of the container \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} docker container rename myweb myalpine & Change the name of a container \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} docker container run -h alpine -it -{}-rm alpine sh & Set the hostnameof a container \tn % Row Count 23 (+ 3) % Row 10 \SetRowColor{LightBackground} docker container run -it -w /var -{}-rm alpine sh & Set the current working directory \tn % Row Count 26 (+ 3) % Row 11 \SetRowColor{white} docker container run -it -{}-env \seqsplit{"WEB\_HOST=172.168.1.1"} -{}-rm alpine sh & Set the environment variables \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Container Operations (cont)}} \tn % Row 12 \SetRowColor{LightBackground} docker container exec myalpine {[}command{]} & Create any process inside an already running container \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Management}} \tn % Row 0 \SetRowColor{LightBackground} docker version & prints the current version number \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker info & displays system wide information \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker login & Log in to a DockerHub registry \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker logout & Logout from DockerHub registry \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} docker inspect {[}object{]} & Display detailed information on one or more objects. \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} docker -{}-help & list the help on any command \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} docker image {[}option{]} & To work with images \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} docker container {[}option{]} & To work with containers \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} docker volume {[}option{]} & To work with volumes \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} docker network {[}option{]} & To work with network \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{List}} \tn % Row 0 \SetRowColor{LightBackground} docker image ls & List of images \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker image ls -{}-digests & List of image digests \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} docker container ls & List of running containers \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker container ls -a & List of all containers \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} docker container ls -q & Get only the containers IDs of containers \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} docker volume ls & List of volumes \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} docker network ls & List of networks \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Images}} \tn % Row 0 \SetRowColor{LightBackground} docker search nginx & List the available images on DockerHub \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker image pull nginx & Pull an image from DockerHub \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker image pull \seqsplit{myregistry.com:8080/alpine:latest} & Pull an image from a private registry \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} vim Dokerfile \{\{nl\}\} FROM alpine \{\{nl\}\} RUN date \textgreater{} /data & {\bf{Dockerfile}} to build an image \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} docker image build -t \seqsplit{php/alpine:dockerfile} . & Create an image from a Dockerfile \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} docker container run -it -{}-name myimage alpine sh \{\{nl\}\} / \# date \textgreater{} /data \{\{nl\}\} / \# cat /data & Run a container and modify it. \tn % Row Count 18 (+ 5) % Row 6 \SetRowColor{LightBackground} docker container diff myimage & Check the difference with the base image \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} docker container commit myimage php/alpine:test & Save a running container as an image. \tn % Row Count 23 (+ 3) % Row 8 \SetRowColor{LightBackground} docker container run -it php/alpine:test sh \{\{nl\}\} cat /data & Run the created image as a container \tn % Row Count 26 (+ 3) % Row 9 \SetRowColor{white} docker image push php/alpine:test & Push the image to DockerHub registry \tn % Row Count 28 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Volumes}} \tn % Row 0 \SetRowColor{LightBackground} docker container run -itv /data -{}-name myvol alpine sh & Create a directory on the host system and mount it under /data of the container \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} docker volume create -{}-name myvolume & Create a named volume \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} docker container run -itv myvolume:/data -{}-name cmyvol alpine sh & Mount a named volume \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} docker system df & Get the information about disk storage \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Networking}} \tn % Row 0 \SetRowColor{LightBackground} docker container run -d -{}-name myweb -p 8080:80 nginx & Access the container from the external world \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker container run -d -{}-name myweb1 -P nginx:alpine & Expose a container port to a random port of the host system \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} docker container run -it -{}-network=none alpine sh & To Request Docker daemon not to create an interface for the container \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} docker container run -it -{}-network=host alpine sh & share the network namespace of the host system with the container \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} docker container run -it -{}-network=container:myweb1 alpine sh & Share the network namespace of an existing container \tn % Row Count 18 (+ 4) % Row 5 \SetRowColor{white} docker network create mynetwork & Create a user defined network \tn % Row Count 20 (+ 2) % Row 6 \SetRowColor{LightBackground} docker container run -d -{}-name nginxnet -{}-network=mynetwork nginx:alpine & Create a container and attach it to the network \tn % Row Count 24 (+ 4) % Row 7 \SetRowColor{white} docker network connect mynetwork web & Attach a running container to a network \tn % Row Count 26 (+ 2) % Row 8 \SetRowColor{LightBackground} docker network disconnect mynetwork web & Disconnect from a specific network \tn % Row Count 28 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Resource Allocation}} \tn % Row 0 \SetRowColor{LightBackground} docker container run -it -{}-ulimit nproc=10 -{}-rm alpine sh & Set the maximum number of processes the container can create \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker container run -d -{}-name cpulimit -{}-cpuset-cpus="0" alpine top & Container can run only on CPU "0". \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} docker container run -d -{}-name memlimit -{}-memory "200m" alpine top & Limit the maximum amount of memory usage \tn % Row Count 11 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Docker Compose}} \tn % Row 0 \SetRowColor{LightBackground} curl -L \seqsplit{"https://github.com/docker/compose/releases/download/1.27.4/docker-compose-\$(uname} -s)-\$(uname -m)" -o \seqsplit{/usr/local/bin/docker-compose} & Install a docker compose \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} chmod +x \seqsplit{/usr/local/bin/docker-compose} & Set the executable \tn % Row Count 9 (+ 2) % Row 2 \SetRowColor{LightBackground} mkdir wordpress\{\{nl\}\}cd wordpress/\{\{nl\}\}vim docker-compose.yaml & Create a folder and yaml file \tn % Row Count 13 (+ 4) % Row 3 \SetRowColor{white} docker-compose up & Start the application in the foreground \tn % Row Count 15 (+ 2) % Row 4 \SetRowColor{LightBackground} docker-compose up -d & Start the application in the background \tn % Row Count 17 (+ 2) % Row 5 \SetRowColor{white} docker-compose ps & List containers created by the application \tn % Row Count 20 (+ 3) % Row 6 \SetRowColor{LightBackground} docker-compose stop & Stop all the containers for the given application \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Clean Up}} \tn % Row 0 \SetRowColor{LightBackground} docker image rm nginx:alpine & Remove an image locally \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker image prune & Clean an unused/dangling image \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker container rm -f web & Delete a running container \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker container rm myweb & Delete a stopped container \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} docker container prune & Remove all stopped containers \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} docker network rm mynetwork & Remove a specific network \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} docker network prune & Remove all networks which are not referenced by any containers \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} docker volume rm myvolume & Remove a specific volume \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} docker volume prune & Remove all unused volume \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} docker-compose rm & Remove the containers for the given application \tn % Row Count 22 (+ 3) % Row 10 \SetRowColor{LightBackground} docker-compose down -v & Delete the application completely with its containers, networks, volumes and images \tn % Row Count 26 (+ 4) % Row 11 \SetRowColor{white} docker system prune & Remove unused images, stopped containers, and unused networks \tn % Row Count 29 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}