\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{mcz} \pdfinfo{ /Title (dockerexp1.pdf) /Creator (Cheatography) /Author (mcz) /Subject (dockerexp1 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}{0270C4} \definecolor{LightBackground}{HTML}{EFF6FB} \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{dockerexp1 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{mcz} via \textcolor{DarkBackground}{\uline{cheatography.com/85452/cs/20039/}}} \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}mcz \\ \uline{cheatography.com/mcz} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 17th November, 2020.\\ 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.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Start}} \tn % Row 0 \SetRowColor{LightBackground} docker version & get the docker version \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker run hello-world & check if everething works \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} docker run -d redis & -d for run in background (detach mode) \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker ps & show all runs. `ps` stands for 'process status' \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} docker ps -a & show all run / paused / stoped \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} docker stop CONTNAME & stop a running container with his name \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} docker rm CONTNAME & remove the instance \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} docker rm \$(docker ps -a -q) & remove all listed instances \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} docker system prune & Erase all /!\textbackslash{} use for big clean \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} docker kill CONTNAME & stop close nicely with maybe some save, message etc Kill will kill now \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{DOCKER IMAGE}} \tn % Row 0 \SetRowColor{LightBackground} docker image ls & List all your images \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Useful flags}} \tn % Row 0 \SetRowColor{LightBackground} ls & List running \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ls -{}-all & List all \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} ls -aq & List all in quiet mode \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{REDIS}} \tn % Row 0 \SetRowColor{LightBackground} docker run redis & will start the redis image \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker exec -it 0c04f252f8d2 redis-cli & In an other terminal run this command to access the redis instance with redis-cli \tn % Row Count 7 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{exec : execute multi command \newline -it : interactive mode == -i -t : (-i attach to stdin) (-t is use to format nicely what you see)} \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}{USEFUL COMMANDS}} \tn % Row 0 \SetRowColor{LightBackground} docker cp folder/test.txt CONTNAME:/path & CP - Copy file to/from docker container: \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker image inspect IMAGENAME & INSPECT - use to inspect info about an image \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} docker logs & Access to logs useful when build, run fail \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{DELETE IMAGES \& CONTAINERS}} \tn % Row 0 \SetRowColor{LightBackground} docker rmi \textless{}your-image-id\textgreater{} & delete docker image (no container linked) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker container rm \textless{}container\_id\_1\textgreater{} & Delete container \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker image prune -a & delete all images \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker container prune & delete all stopped containers \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}{Working with volume}} \tn % Row 0 \SetRowColor{LightBackground} VOLUME {[}"app/tempfile"{]} & Add anonymous volume for temp files in Dockerfile \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} docker volume ls & List all volumes available \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} docker run -p 3000:3000 -{}-rm -{}-name test-app -v tosave:app/saveme imageName:info & Create a named volume to get data persistant \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} docker volume rm VOL\_NAME & To delete a specific volume \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} docker volume prune & To clear al volumes \tn % Row Count 12 (+ 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}{ENV \& ARG}} \tn % Row 0 \SetRowColor{LightBackground} ENV {\emph{name}} {\emph{value}} & is use on docker file \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} -{}-env PORT=3000 or -e PORT=3000 & is use on `docker run` (overwrite dockerfile) \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} -{}-env-file .env & on`docker run` use a file to define env variable \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} ARG DEFAULT\_PORT=80 & is use on dockerfile for the image build \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} ENV PORT \$DEFAULT\_PORT & ex of use ARG in dockerfile \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} docker build -app:1 -{}-build-arg DEFAULT\_PORT=3000 & Change ARG in dockerfile on build with `-{}-build-arg` \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{TIPS 1 - CREATE START LOGS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{docker run = docker create + docker start} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker create hello-world & return a container id \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} docker start -a 456789123dj.. & -a mean get output to my terminal \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker logs 456789123dj.. & print the logs when not use the -a \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{456789123dj.. is the container id} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{TIPS 2 - EXEC -it SH}} \tn % Row 0 \SetRowColor{LightBackground} docker exec -it 0c04f252f8d2 sh & open a shell in a running container \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} cmd + d or type `exit` & exit the shell \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} docker run -it busybox sh & attach stdin stdout \& run shell \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{DOCKERFILE}} \tn % Row 0 \SetRowColor{LightBackground} Create a `Dockerfile` & FROM WORKDIR COPY RUN EXPOSE CMD \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker build . & run this command to build your image \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} =\textgreater{} Successfully built b3cc42a9ef20 & Return you the image id \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} docker build -t myredis . & Add a tag to the image \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} mcz/redis:latest & tag convention: \seqsplit{dockerid/projectname:version} \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} FROM node:alpine & take the node base image \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} COPY ./ ./ & copy all file inside our project \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} WORKDIR /user/app & Set a default safe directory to pull files \tn % Row Count 18 (+ 3) % Row 8 \SetRowColor{LightBackground} RUN npm install & node classic action \tn % Row Count 19 (+ 1) % Row 9 \SetRowColor{white} ENV PORT 3000 & Use env variable in your docker file `EXPOSE \$PORT`` \tn % Row Count 22 (+ 3) % Row 10 \SetRowColor{LightBackground} CMD {[}"npm", "start"{]} & Script start in package.json \tn % Row Count 24 (+ 2) % Row 11 \SetRowColor{white} docker build -t john/nodeserver . & Build image with a tag name \tn % Row Count 26 (+ 2) % Row 12 \SetRowColor{LightBackground} docker run -p 8080:8080 john/nodeserver & Set port mapping to enable incoming traffic \tn % Row Count 29 (+ 3) % Row 13 \SetRowColor{white} docker ps & list running container with id \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{DOCKERFILE (cont)}} \tn % Row 14 \SetRowColor{LightBackground} docker exec -it c6632338e690 sh & Get a shell inside your running container \tn % Row Count 3 (+ 3) % Row 15 \SetRowColor{white} docker build -f Dockerfile.dev & To run a dev version called Dockerfile.dev \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{DOCKER COMPOSE}} \tn % Row 0 \SetRowColor{LightBackground} docker-compose & List all cmd available \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker-compose up & like `docker run` \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} docker-compose up -{}-build & build image + run \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} docker-compose up -d & With -d run in background \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} docker-compose down & Stop the containers \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} restart: on-failure & LIST OF RESART CMD \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} "no" & never restart \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} always & restart anyway \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} on-failure & restart on process.exit(34) value \textgreater{} 0 \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} unless-stoped & always unless the dev stop \tn % Row Count 17 (+ 2) % Row 10 \SetRowColor{LightBackground} docker-compose ps & Only works in the current directory \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Terminology}} \tn % Row 0 \SetRowColor{LightBackground} SIGTERM & terminate signal \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} SIGKILL & Kill signal \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}