\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{Cash (CashM)} \pdfinfo{ /Title (devcodecamp-docker-commands-inclusive.pdf) /Creator (Cheatography) /Author (Cash (CashM)) /Subject (devCodeCamp Docker Commands (Inclusive) 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}{A34007} \definecolor{LightBackground}{HTML}{F9F3EF} \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{devCodeCamp Docker Commands (Inclusive) Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Cash (CashM)} via \textcolor{DarkBackground}{\uline{cheatography.com/123081/cs/30565/}}} \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}Cash (CashM) \\ \uline{cheatography.com/cashm} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 23rd January, 2022.\\ Updated 28th January, 2022.\\ 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{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Basic Docker commands}} \tn % Row 0 \SetRowColor{LightBackground} docker -{}-help & Displays basic help options and commands \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker \textless{}command\textgreater{} -{}-help & Display detailed help for a specific command \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker ps & List of "live" containers \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} docker ps -a/-all & List of all containers \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} docker version & Display docker versioning \tn % Row Count 8 (+ 1) \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 commands}} \tn % Row 0 \SetRowColor{LightBackground} docker run \textless{}image\textgreater{} & Builds a docker image from the Docker file \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker run {[}options{]} \textless{}image:tag@digest\textgreater{} \textless{}command\textgreater{} \textless{}arguments\textgreater{} & Full syntax of docker run command \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} docker create \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Creates a container using the image \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} docker start \textless{}container\textgreater{} & Starts a container \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} docker stop \textless{}container\textgreater{} & Stops a container in an orderly manner \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} docker kill \textless{}container\textgreater{} & Immediately stops a running container \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} docker restart \textless{}container\textgreater{} & Restarts a stopped container \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} docker rm \textless{}container\textgreater{} & Removes a stopped container \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} docker port \textless{}container\textgreater{} & Lists the port mapping of a "running" container \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\textless{}container\textgreater{} can be replaced with the containers unique {\bf{ID}} or unique {\bf{NAME}} \newline \textless{}tag\textgreater{} is optional and will default to {\emph{latest}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Image Commands}} \tn % Row 0 \SetRowColor{LightBackground} docker images & List images \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker run \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Builds a new container using the image \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} docker build \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Builds a docker image from the Docker file \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker rmi \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Remove an image (not attached to a container) \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} docker save \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Saves an image to a {\emph{tar}} archive \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} docker push \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Pushes the image to Docker Hub \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} docker pull \textless{}image\textgreater{}:\textless{}tag\textgreater{} & Pulls the image from Docker Hub \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\textless{}image\textgreater{} can be replaced with the images unique {\bf{ID}} or or unique {\bf{NAME}} \newline \textless{}tag\textgreater{} is optional and will default to {\emph{latest}}} \tn \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}{Miscellaneous Commands}} \tn % Row 0 \SetRowColor{LightBackground} docker exec -it \textless{}container\textgreater{} \textless{}entrypoint\textgreater{} & Executes the command or terminal of a running container \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker inspect \textless{}image or container\textgreater{} & Returns low level information on an image or a container \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} docker attach \textless{}container\textgreater{} & Attach to a running container \tn % Row Count 8 (+ 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}{Option Keywords}} \tn % Row 0 \SetRowColor{LightBackground} -i, -{}-interactive & Keep STDIN open even if not attached \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} -t, -{}-tty & Allocate a psuedo-TTY \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} -it & Combines the -i and the -t options (interactive response) \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} -a, -{}-attach & attach \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} -d, -{}-detach & Run in background \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} -e, -{}-env & Set ENV variables \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} exec & Run a new command in a container (See Misc) \tn % Row Count 13 (+ 3) % Row 7 \SetRowColor{white} -p, -publish \textless{}host\_port\textgreater{}\textgreater{}:\textless{}container\_port\textgreater{} & Port mapping (Host to container) \tn % Row Count 16 (+ 3) % Row 8 \SetRowColor{LightBackground} -v, -{}-volume \textless{}source\textgreater{}:\textless{}target\textgreater{} & Mount files or directories (terse) \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} -m, -{}-mount & Mount files or directores (verbose) \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2 cm} x{6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Arguments}} \tn % Row 0 \SetRowColor{LightBackground} -{}-name=\textless{}name\textgreater{} & Assigns a name to a container: {\emph{docker run -{}-name=\textless{}name\textgreater{} \textless{}image\textgreater{}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} -a, -{}-all & Adds the option of "all" to the container list: {\emph{docker ps -a}} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} sh & Entrypoint command for a {\bf{shell}} in a container: {\emph{docker run -it \textless{}image\textgreater{} {\bf{sh}} }} or {\emph{docker exec -it \textless{}container\textgreater{} {\bf{sh}} }} \tn % Row Count 11 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.12 cm} x{2.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Volume Commands}} \tn % Row 0 \SetRowColor{LightBackground} docker volume ls & List volumes \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker volume inspect & Inspect a volume \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} docker volume create \textless{}volume\textgreater{} & Create a volume \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker volume rm \textless{}volume\textgreater{} & Removes a volume \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\textless{}volume\textgreater{} can be replaced with the volumes unique {\bf{ID}} or unique {\bf{NAME}}} \tn \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}{Dockerfile (for creating images)}} \tn % Row 0 \SetRowColor{LightBackground} FROM \textless{}image\textgreater{} {[}AS \textless{}name\textgreater{}{]} & Sets the base image for this layered imaged \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} RUN \textless{}command\textgreater{} & (Shell form) Executes commands in a new layer \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} RUN {[}"executable", "param1", "param2"{]} & (Exec form) Executes commands in a new layer \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} CMD {[}"executable", "param1", "param2"{]} & (Exec form) Sets default executable as the ENTRYPOINT \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} CMD {[}"param1", "param2"{]} & (adds default parameters to non-specified ENTRYPOINT) \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} CMD command param1 param2 & (shell form) \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} LABEL \textless{}key\textgreater{}=\textless{}value\textgreater{} \textless{}key\textgreater{}=\textless{}value\textgreater{} ... & Adds metadata to an image \tn % Row Count 19 (+ 2) % Row 7 \SetRowColor{white} EXPOSE \textless{}port\textgreater{} {[}\textless{}ports\textgreater{}/\textless{}protocol\textgreater{}{]} & Specifys the port(s) for the container to listen on \tn % Row Count 22 (+ 3) % Row 8 \SetRowColor{LightBackground} ENV \textless{}key\textgreater{}=\textless{}value & Sets an environment variable for all subsequent instructions \tn % Row Count 25 (+ 3) % Row 9 \SetRowColor{white} COPY {[}-{}-chown=\textless{}usr\textgreater{}:\textless{}group\textgreater{}{]} \textless{}src\textgreater{}... \textless{}dest\textgreater{} & Copies files or directorys from \textless{}src\textgreater{} and adds them to the container at \textless{}dest\textgreater{} \tn % Row Count 29 (+ 4) % Row 10 \SetRowColor{LightBackground} VOLUME {[}"/data"{]} & (Can be an array) Creates a mount point for files or directories \tn % Row Count 33 (+ 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}{Dockerfile (for creating images) (cont)}} \tn % Row 11 \SetRowColor{LightBackground} USER \textless{}user\textgreater{}{[}:\textless{}group\textgreater{}{]} & Sets the user name and optionally the user group to use when running image \tn % Row Count 4 (+ 4) % Row 12 \SetRowColor{white} WORKDIR & Sets the working directory \tn % Row Count 6 (+ 2) % Row 13 \SetRowColor{LightBackground} ARG \textless{}NAME\textgreater{}=\textless{}value\textgreater{} & ARG is the only command that may precede the FROM command. It sets support variables for the FROM \tn % Row Count 11 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Basic Dockerfile Dev Structure}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{From \textless{}image\textgreater{}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{WORKDIR \textless{}path\textgreater{}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{[}ENV \textless{}key\textgreater{}=\textless{}value\textgreater{}{]}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{COPY \textless{}src\textgreater{} \textless{}target\textgreater{}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{RUN command param1 param2 ...} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{CMD {[}"executable", "param1", "param2", ...{]}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}