\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{Gaurav Pandey (gauravpandey44)} \pdfinfo{ /Title (docker-swarm.pdf) /Creator (Cheatography) /Author (Gaurav Pandey (gauravpandey44)) /Subject (Docker Swarm 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}{A30D0D} \definecolor{LightBackground}{HTML}{FCF7F7} \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 Swarm Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Gaurav Pandey (gauravpandey44)} via \textcolor{DarkBackground}{\uline{cheatography.com/69622/cs/20590/}}} \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}Gaurav Pandey (gauravpandey44) \\ \uline{cheatography.com/gauravpandey44} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 22nd September, 2019.\\ Updated 22nd September, 2019.\\ 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Basic}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Swarm}} is Docker's in built containers orchestrator solution, its main purpose is to manage containers in a computer cluster, i.e. a set of connected computers that work together. \newline % Row Count 4 (+ 4) Swarm comes built into the Docker Engine, you don't need to install anything to get started.% Row Count 6 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{In Docker, there are many layers of encapsulation: the OS kernel, containers, tasks that encapsulate containers as units of work, services or Pods that represent application components, and stacks(collection of services) that represent full applications.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.08 cm} x{3.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{docker swarm commands}} \tn % Row 0 \SetRowColor{LightBackground} docker swarm init & Initialize a swarm \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} docker swarm join -{}-token\textless{}manager-token\textgreater{} 10.1.0.2:2377 & Join an existing swarm as manager node \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} docker swarm join -{}-token\textless{}worker-token\textgreater{} 10.1.0.2:2377 & Join a swarm as a worker node \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} docker swarm leave & Leave the swarm \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}{docker stack commands}} \tn % Row 0 \SetRowColor{LightBackground} docker stack deploy nodeapp -c docker-compose.yml & deploy the stack using docker-compose file , Swarm does not support the build option if defined in the Compose file(but docker compose up uses it). \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} docker stack ls & shows all stacks along with list of services in the stack \tn % Row Count 11 (+ 3) % Row 2 \SetRowColor{LightBackground} docker stack services \textless{}stack-name\textgreater{} & list the services in the stack. \tn % Row Count 13 (+ 2) % Row 3 \SetRowColor{white} docker stack ps \textless{}stack-name\textgreater{} & list all the tasks in the stack. \tn % Row Count 15 (+ 2) % Row 4 \SetRowColor{LightBackground} docker stack rm \textless{}stack-name\textgreater{} & removes the stack. \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Manage Docker stacks( is a collection of services that make up an application in a specific environment).} \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}{docker service commands}} \tn % Row 0 \SetRowColor{LightBackground} docker service create -{}-replicas 5 -p 80:80 -{}-name web nginx & create docker service directly (similar to docker run command) \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} docker service logs {[}OPTIONS{]} SERVICE|TASK & Fetch the logs of a service or task, in option you can use -f,-{}-details etc \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} docker service ls & list all the services \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} docker service ps {[}OPTIONS{]} SERVICE {[}SERVICE...{]} & List the tasks of one or more services \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} docker service rm SERVICE {[}SERVICE...{]} & Remove one or more services \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} docker service scale SERVICE=REPLICAS {[}SERVICE=REPLICAS...{]} & Scale one or multiple replicated services \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} docker service update {[}OPTIONS{]} SERVICE & Update a service \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Manage services.Services in the swarm mode are actually object (when compared to the docker compose services where they are actual running services)} \tn \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}{docker node commands}} \tn % Row 0 \SetRowColor{LightBackground} docker node ls & List nodes in the swarm \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} docker node ps & List tasks running on one or more nodes, defaults to current node \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} docker node rm {[}OPTIONS{]} NODE {[}NODE...{]} & Remove one or more nodes from the swarm \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} docker node demote NODE {[}NODE...{]} & Demote one or more nodes from manager in the swarm \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} docker node promote NODE {[}NODE...{]} & Promote one or more nodes to manager in the swarm \tn % Row Count 15 (+ 3) \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}{Common Terms/Key concepts}} \tn % Row 0 \SetRowColor{LightBackground} Node & is a physical or virtual machine (running an instance of the Docker Engine.) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Manager nodes & perform swarm management and orchestration duties. By default manager nodes are also worker nodes. \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} Worker nodes & execute tasks. \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} Cluster & one or more nodes grouped together. \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} Swarm & is a type of cluster in docker terminology. \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} Docker Swarm & (not part of docker engine)is a separate product which you can use to cluster multiple Docker hosts. Prior to Docker version 1.12 it was the only native Docker option for clustering hosts, and it needed a lot of additional setup for distributed state, service discovery and security. \tn % Row Count 23 (+ 10) % Row 6 \SetRowColor{LightBackground} Swarm Mode & With Docker 1.12,(is built into Docker Engine) To run a cluster you just need to install Docker on multiple machines, run docker swarm init to switch to Swarm Mode and docker swarm join to add more nodes to the cluster. State, discovery and security are all included with zero setup. \tn % Row Count 33 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2 cm} x{6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Common Terms/Key concepts (cont)}} \tn % Row 7 \SetRowColor{LightBackground} Stack & is a collection of services that make up an application in a specific environment. \tn % Row Count 3 (+ 3) % Row 8 \SetRowColor{white} service & it defines the blueprint about which image to use and which commands to execute,ports,networks,replicas,etc inside future running containers. \tn % Row Count 8 (+ 5) % Row 9 \SetRowColor{LightBackground} task & in swarm model,task is actually invoked inside a container.When service is created the swarm manager starts a task(or its replicas) inside various containers. \tn % Row Count 14 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Swarm service diagram}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/gauravpandey44_1569177694_services-diagram.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Application}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/gauravpandey44_1569183726_hello-docker-with-swarm.001.jpeg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{similar commands}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Init host as a swarm manager node}}: \newline docker swarm init \newline {\bf{Deploy application}}: \newline docker stack deploy -c docker-compose.yml myApp \newline {\bf{List services}}: \newline docker service ls \newline docker stack services myApp \newline {\bf{List tasks}}: \newline docker service ps myApp\_web \newline docker container ls -q \newline docker stack ps myApp \newline {\bf{Stop application}}: \newline docker stack rm myApp \newline {\bf{Take down swarm}} \newline docker swarm leave -{}-force} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}