\documentclass[DIV=12,%
               BCOR=0mm,%
               headinclude=false,%
               footinclude=false,open=any,%
               fontsize=10pt,%
               oneside,%
               paper=210mm:11in]%
               {scrbook}






\usepackage[noautomatic]{imakeidx}



\usepackage{microtype}
\usepackage{graphicx}
\usepackage{alltt}
\usepackage{verbatim}
\usepackage[shortlabels]{enumitem}
\usepackage{tabularx}
\usepackage[normalem]{ulem}
\def\hsout{\bgroup \ULdepth=-.55ex \ULset}
% https://tex.stackexchange.com/questions/22410/strikethrough-in-section-title
% Unclear if \protect \hsout is needed. Doesn't looks so
\DeclareRobustCommand{\sout}[1]{\texorpdfstring{\hsout{#1}}{#1}}
\usepackage{wrapfig}

% avoid breakage on multiple <br><br> and avoid the next [] to be eaten
\newcommand*{\forcelinebreak}{\strut\\*{}}

\newcommand*{\hairline}{%
  \bigskip%
  \noindent \hrulefill%
  \bigskip%
}

% reverse indentation for biblio and play

\newenvironment*{amusebiblio}{
  \leftskip=\parindent
  \parindent=-\parindent
  \smallskip
  \indent
}{\smallskip}

\newenvironment*{amuseplay}{
  \leftskip=\parindent
  \parindent=-\parindent
  \smallskip
  \indent
}{\smallskip}

\newcommand*{\Slash}{\slash\hspace{0pt}}


% http://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url
\PassOptionsToPackage{hyphens}{url}\usepackage[hyperfootnotes=false,hidelinks,breaklinks=true]{hyperref}
\usepackage{bookmark}

\usepackage[english,shorthands=off]{babel}
\babelfont{rm}[Path=/home/wiki/.fonts/cm-unicode/,%
 BoldFont=cmunbx.otf,%
 BoldItalicFont=cmunbi.otf,%
 ItalicFont=cmunti.otf]{cmunrm.otf}
\babelfont{tt}[Scale=MatchLowercase,%
 Path=/home/wiki/.fonts/cm-unicode/,%
 BoldFont=cmuntb.otf,%
 BoldItalicFont=cmuntx.otf,%
 ItalicFont=cmunit.otf]{cmuntt.otf}
\babelfont{sf}[Scale=MatchLowercase,%
 Path=/home/wiki/.fonts/cm-unicode/,%
 BoldFont=cmunsx.otf,%
 BoldItalicFont=cmunso.otf,%
 ItalicFont=cmunsi.otf]{cmunss.otf}



\renewcommand*{\partpagestyle}{empty}


% global style

\pagestyle{plain}




\usepackage{indentfirst}

% remove the numbering
\setcounter{secnumdepth}{-2}

% remove labels from the captions
\renewcommand*{\captionformat}{}
\renewcommand*{\figureformat}{}
\renewcommand*{\tableformat}{}
\KOMAoption{captions}{belowfigure,nooneline}
\addtokomafont{caption}{\centering}







\deffootnote[3em]{0em}{4em}{\textsuperscript{\thefootnotemark}~}


\addtokomafont{disposition}{\rmfamily}
\addtokomafont{descriptionlabel}{\rmfamily}


\frenchspacing
% avoid vertical glue
\raggedbottom

% this will generate overfull boxes, so we need to set a tolerance
% \pretolerance=1000
% pretolerance is what is accepted for a paragraph without
% hyphenation, so it makes sense to be strict here and let the user
% accept tweak the tolerance instead.
\tolerance=200
% Additional tolerance for bad paragraphs only
\setlength{\emergencystretch}{30pt}

% (try to) forbid widows/orphans
\clubpenalty=10000
\widowpenalty=10000





% given that we said footinclude=false, this should be safe
\setlength{\footskip}{2\baselineskip}
\setlength{\parindent}{15pt}

\title{Docker Cheatsheet}
\date{}
\author{Stefan Hornburg (Racke)}
\subtitle{}






% https://groups.google.com/d/topic/comp.text.tex/6fYmcVMbSbQ/discussion
\hypersetup{%
pdfencoding=auto,
pdftitle={Docker Cheatsheet},%
pdfauthor={Stefan Hornburg (Racke)},%
pdfsubject={},%
pdfkeywords={Docker}%
}


\begin{document}









  \begin{titlepage}


  \strut\vskip 2em
  \begin{center}

  {\usekomafont{title}{\huge Docker Cheatsheet\par}}%
  \vskip 1em
  
  \vskip 2em
  
  {\usekomafont{author}{Stefan Hornburg (Racke)\par}}%
  
  \vskip 1.5em



   
   \vfill



  
    \strut\par
  


  \end{center}


     \end{titlepage}
     
     \cleardoublepage





\tableofcontents
% start a new right-handed page

\cleardoublepage



\chapter{Images}

\section{Building images}


\begin{alltt}
\$ docker build -t myimage:0.001 .
\end{alltt}


Use a different Dockerfile:


\begin{alltt}
\$ docker build -t myimage:0.001 -f Dockerfile.myimage .
\end{alltt}


Skipping cache:


\begin{alltt}
\$ docker build --no-cache -t myimage:0.001 .
\end{alltt}

\section{Prune images}


Delete all images without an associated container:


\begin{alltt}
\$ docker image prune
\end{alltt}

\section{Inspect images}


In order to inspect the images, you may run them as container with a shell command - usually \emph{bash} but \emph{sh} for Alpine based ones:


\begin{alltt}
\$ docker run -it myimage:0.001 bash
\end{alltt}

\chapter{Containers}

\section{Run from image}


\begin{alltt}
\$ docker run --name sympa -d -i sympa:6.2.48
\end{alltt}


Explanation:


\begin{description}

\item[{-d}] 
detached


\item[{-i}] 
image tag


\item[{--name}] 
name of the container (optional)


\end{description}

You can instruct Docker to automatically remove the container when it is terminated
by adding the \texttt{--rm} flag:


\begin{alltt}
\$ docker run --rm --name sympa -d -i sympa:6.2.48
\end{alltt}


Please note that this also removes the logs for the container.


Environment variables can be passed to the container with the \texttt{--env} flag:


\begin{alltt}
\$ docker run --env SYMPA\_DB\_USER=sympa --env SYMPA\_DB\_PASSWORD=sympa --name sympa -d -i sympa:6.2.48
\end{alltt}

\section{Remove and prune}

\subsection{Remove container}


\begin{alltt}
docker rm sympa
\end{alltt}


Please note that the corresponding image isn't affected.

\subsection{Prune containers}


Remove all stopped containers:


\begin{alltt}
\$ docker container prune
\end{alltt}


Remove all stopped containers older than a day:


\begin{alltt}
\$ docker container prune --filter "until=24h"
\end{alltt}

\section{Shell on a running container}


\begin{alltt}
\$ docker exec -it 593d9b3219c6 bash
\end{alltt}


You can also pass environment variables to the command executed in the Docker container:


\begin{alltt}
\$ docker exec -e SPACEWALK\_API\_USER=admin -e SPACEWALK\_API\_PASS=nevairbe -it spacewalk /bin/setup-spacecmd.sh
\end{alltt}


Note: the flags for the environment preceed the flag for the container.

\section{Copy files from\Slash{}to container}


From:


\begin{alltt}
\$ docker cp wp-site:/var/www/html/wp-config.php .
\end{alltt}


To:


\begin{alltt}
\$ docker cp  ./setup-spacecmd.sh spacewalk2:/bin
\end{alltt}

\section{Logs}


To see the log messages for the container \emph{nginx}:


\begin{alltt}
\$ docker logs nginx
\end{alltt}


However, this shows only the messages without any further information.


You can add the timestamp with the \texttt{--timestamps} commandline option:


\begin{alltt}
\$ docker logs --timestamps nginx
\end{alltt}


Show the latest 30 entries:


\begin{alltt}
\$ docker logs --tail 30 nginx
\end{alltt}


Follow new entries:


\begin{alltt}
\$ docker logs --tail 0 nginx --follow
\end{alltt}

\chapter{Container Information}

\section{IP address}


To get the IP address of the container \emph{perldancer}:


\begin{alltt}
\$ docker inspect -f '\{\{range .NetworkSettings.Networks\}\}\{\{.IPAddress\}\}\{\{end\}\}' perldancer
\end{alltt}

\section{Determine whether a container is running properly}


This checks whether the container with the name \emph{sympa} is active \textbf{and} running, e.g. not restarting because of a problem with the command it executes on startup.


\begin{alltt}
\$ docker ps -q --filter=name='/sympa\$' --filter=status=running
\end{alltt}

\chapter{Startup problems}


\begin{itemize}
\item\relax 
Missing environment variables, e.g. \texttt{MYSQL\_ROOT\_PASSWORD} for \emph{mysql} container




\end{itemize}
\chapter{Compose}


Run containers and detach:


\begin{alltt}
\$ docker-compose up -d
\end{alltt}









% begin final page

\clearpage



% new page for the colophon

\thispagestyle{empty}

\begin{center}

Linuxia Wiki





\strut

\end{center}

\strut

\vfill

\begin{center}


Stefan Hornburg (Racke)

Docker Cheatsheet






\bigskip



   

       

       

       

       

       

       

   



\bigskip
\textbf{wiki.linuxia.de}


\end{center}

% end final page with colophon


% end closing pages



\end{document}


% No format ID passed.



