1"use strict";(self.webpackChunkpt_4_docusaurus=self.webpackChunkpt_4_docusaurus||[]).push([[676],{729:(e,s,n)=>{n.d(s,{A:()=>t});const t=n.p+"assets/files/red_hat_developer_docker_cheat_sheet-2cd30a8cb39cb501034ac3c21ee84153.pdf"},791:e=>{e.exports=JSON.parse('{"permalink":"/blog/docker-commands-cheat-sheet","editUrl":"https://github.com/pagertree/pt4-docusaurus/tree/main/blog/docker-commands-cheat-sheet.md","source":"@site/blog/docker-commands-cheat-sheet.md","title":"\u2728 Docker Commands Cheat Sheet","description":"Docker Commands Cheat Sheet - A quick reference guide to Docker CLI commands used on a daily basis: usage, examples, snippets and links.","date":"2022-12-15T00:00:00.000Z","tags":[],"readingTime":7.25,"hasTruncateMarker":true,"authors":[{"name":"Austin Miller","title":"Founder of PagerTree","url":"https://www.linkedin.com/in/austin-miller-b2b43b36/","imageURL":"https://avatars.githubusercontent.com/u/9020194?v=4","key":"amiller","page":null}],"frontMatter":{"date":"2022-12-15T00:00:00.000Z","authors":"amiller","description":"Docker Commands Cheat Sheet - A quick reference guide to Docker CLI commands used on a daily basis: usage, examples, snippets and links."},"unlisted":false,"prevItem":{"title":"\ud83d\udce3 Critical Alerts for iOS and iPhone","permalink":"/blog/critical-alerts-for-ios-and-iphone"},"nextItem":{"title":"\ud83d\udea8 Incident Response Alert Routing","permalink":"/blog/incident-response-alert-routing"}}')},1077:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>o,metadata:()=>t,toc:()=>d});var t=n(791),r=n(4848),i=n(8453);const o={date:new Date("2022-12-15T00:00:00.000Z"),authors:"amiller",description:"Docker Commands Cheat Sheet - A quick reference guide to Docker CLI commands used on a daily basis: usage, examples, snippets and links."},a="\u2728 Docker Commands Cheat Sheet",c={authorsImageUrls:[void 0]},d=[{value:"Check Running Containers <a></a>",id:"check-running-containers-",level:2},{value:"SSH Into Container <a></a>",id:"ssh-into-container-",level:2},{value:"Restart A Container <a></a>",id:"restart-a-container-",level:2},{value:"Check CPU and Memory Usage <a></a>",id:"check-cpu-and-memory-usage-",level:2},{value:"Check Disk Space Usage <a></a>",id:"check-disk-space-usage-",level:2},{value:"Prune Images and Volumes <a></a>",id:"prune-images-and-volumes-",level:2},{value:"Docker Links You Might Find Useful <a></a>",id:"docker-links-you-might-find-useful-",level:2},{value:"Images <a></a>",id:"images-",level:3},{value:"Blog Articles <a></a>",id:"blog-articles-",level:3},{value:"PagerTree Cheat Sheets",id:"pagertree-cheat-sheets",level:3},{value:"Cheat Sheets (PDFs) <a></a>",id:"cheat-sheets-pdfs-",level:3}];function l(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",img:"img",li:"li",p:"p",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["In this article I will highlight the ",(0,r.jsx)(s.strong,{children:"6 key docker commands"})," I use on a daily basis while using ",(0,r.jsx)(s.a,{href:"https://www.docker.com/",children:"Docker"})," in the real world."]}),"\n",(0,r.jsx)(s.p,{children:"By no means is this an extensive list of docker commands. I kept it short on purpose so you could use it as a quick reference guide. I\u2019ve also omitted the topic of building images and the commands that are associated with that."}),"\n",(0,r.jsxs)(s.p,{children:["At the bottom of the page, I\u2019ll also put some good links to other Docker resources I like or frequently use as well as other PagerTree cheat sheet documents. For a full crash course, check out our ",(0,r.jsx)(s.a,{href:"https://pagertree.com/learn/docker",children:"Learn Docker Series"}),"!"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Command"}),(0,r.jsx)(s.th,{children:"Short Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"docker ps"})}),(0,r.jsx)(s.td,{children:"List running containers"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"docker exec -it <container name> /bin/sh"})}),(0,r.jsx)(s.td,{children:"SSH into container"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"docker restart <container name>"})}),(0,r.jsx)(s.td,{children:"Restart a container"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"docker stats"})}),(0,r.jsx)(s.td,{children:"Show running container stats"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"docker system df"})}),(0,r.jsx)(s.td,{children:"Check docker daemon disk space usage"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"docker system prune -af"})}),(0,r.jsx)(s.td,{children:"Remove images, networks, containers, and volumes"})]})]})]}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{alt:"Docker Command Cheat Sheet",src:n(8145).A+"",width:"1728",height:"2304"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"See download link below for PDF"})})]}),"\n",(0,r.jsxs)(s.h2,{id:"check-running-containers-",children:["Check Running Containers ",(0,r.jsx)("a",{href:"#check-running-containers",id:"check-running-containers"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Command: ",(0,r.jsx)(s.code,{children:"docker ps"})]}),"\n",(0,r.jsx)(s.li,{children:"Description: Show running containers."}),"\n",(0,r.jsxs)(s.li,{children:["Official Docs: ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/ps/",children:"https://docs.docker.com/engine/reference/commandline/ps/"})]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["Normally I will use this command just as often as I use ",(0,r.jsx)(s.code,{children:"ls"})," command on a *NIX terminal. It\u2019s especially useful when you first SSH to a machine to check what\u2019s running. It\u2019s also useful during the development and configuration process since you\u2019ll likely have containers stopping/starting/crashing."]}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{src:"https://pagertree.com/assets/img/posts/2020/01/06/docker-ps.png",alt:"Docker PS Example Output"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"docker ps Example Output"})})]}),"\n",(0,r.jsxs)(s.h2,{id:"ssh-into-container-",children:["SSH Into Container ",(0,r.jsx)("a",{href:"#ssh-into-container",id:"ssh-into-container"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Command: ",(0,r.jsx)(s.code,{children:"docker exec -it <container name> /bin/sh"})]}),"\n",(0,r.jsx)(s.li,{children:"Description: SSH into a container."}),"\n",(0,r.jsxs)(s.li,{children:["Official Docs: ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/exec/",children:"https://docs.docker.com/engine/reference/commandline/exec/"})]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["This is probably my 2nd most popular command. Normally I am using this while trying to debug a container and need to shell into the container. Just note the ",(0,r.jsx)(s.code,{children:"-i"})," flag means ",(0,r.jsx)(s.strong,{children:"interactive"})," and ",(0,r.jsx)(s.code,{children:"-t"})," means ",(0,r.jsx)(s.strong,{children:"TTY"})," (aka a teletype terminal)."]}),"\n",(0,r.jsxs)(s.p,{children:["Also, you can use any command instead of ",(0,r.jsx)(s.code,{children:"/bin/sh"}),"; I only put that here because I frequently am SSHing into an alpine image which doesn\u2019t support bash."]}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{src:"https://pagertree.com/assets/img/posts/2020/01/06/docker-exec-it.png",alt:"Docker Cheat sheet exec"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"docker exec -it Example Output"})})]}),"\n",(0,r.jsxs)(s.h2,{id:"restart-a-container-",children:["Restart A Container ",(0,r.jsx)("a",{href:"#restart-a-container",id:"restart-a-container"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Command: ",(0,r.jsx)(s.code,{children:"docker restart <container name>"})]}),"\n",(0,r.jsx)(s.li,{children:"Description: Restart a container."}),"\n",(0,r.jsxs)(s.li,{children:["Official Docs: ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/restart/",children:"https://docs.docker.com/engine/reference/commandline/restart/"})]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["I debated putting this command in here, since I don\u2019t use it all that often, but it\u2019s a nice to have. Great example of when to use this - you change your ",(0,r.jsx)(s.a,{href:"https://pagertree.com/blog/prometheus-monitoring-tutorial",children:"prometheus configuration"})," and need it to pick up the changes in your config file. You might also use this when ",(0,r.jsx)(s.a,{href:"https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html",children:"resizing a volume"}),"."]}),"\n",(0,r.jsxs)(s.p,{children:["Other commands you might use often, but I didn\u2019t think were so worthy of their own section are ",(0,r.jsx)(s.code,{children:"docker start"})," (",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/start/",children:"see docs"}),") and ",(0,r.jsx)(s.code,{children:"docker stop"})," (",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/stop/",children:"see docs"}),"). You\u2019ll use these commands normally when setting up or testing images and you\u2019ll likely use a lot of flags. I didn\u2019t think they were so applicable because you should honestly be using ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/compose/",children:"docker
1compose"})," or some other orchestration system (like ",(0,r.jsx)(s.a,{href:"https://aws.amazon.com/ecs/",children:"Amazon ECS"})," or ",(0,r.jsx)(s.a,{href:"https://kubernetes.io/",children:"Kubernetes"}),") to launch your containers."]}),"\n",(0,r.jsxs)(s.h2,{id:"check-cpu-and-memory-usage-",children:["Check CPU and Memory Usage ",(0,r.jsx)("a",{href:"#check-cpu-and-memory-usage",id:"check-cpu-and-memory-usage"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Command: ",(0,r.jsx)(s.code,{children:"docker stats"})]}),"\n",(0,r.jsx)(s.li,{children:"Description: Display a live stream of running containers usage statistics."}),"\n",(0,r.jsxs)(s.li,{children:["Official Docs: ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/stats/",children:"https://docs.docker.com/engine/reference/commandline/stats/"})]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["I\u2019m normally using this command when I am trying to figure out optimal ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/config/containers/resource_constraints/",children:"soft/hard limits"})," for containers. You might also use this if you are debugging which container is using most of your host\u2019s resources."]}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{src:"https://pagertree.com/assets/img/posts/2020/01/06/docker-stats.png",alt:"Docker Stats Example Output"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"docker stats Example Output"})})]}),"\n",(0,r.jsxs)(s.h2,{id:"check-disk-space-usage-",children:["Check Disk Space Usage ",(0,r.jsx)("a",{href:"#check-disk-space-usage",id:"check-disk-space-usage"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Command: ",(0,r.jsx)(s.code,{children:"docker system df"})]}),"\n",(0,r.jsx)(s.li,{children:"Description: Display information about disk space being used by your containers."}),"\n",(0,r.jsxs)(s.li,{children:["Official Docs: ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/system_df/",children:"https://docs.docker.com/engine/reference/commandline/system_df/"})]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["This one doesn\u2019t come up to often, but it has, especially when you are building lots of images on a box or you are storing lots of data (like ",(0,r.jsx)(s.a,{href:"https://pagertree.com/blog/prometheus-monitoring-tutorial",children:"prometheus"}),"). If you are, you might consider setting up a cron job to ",(0,r.jsx)(s.a,{href:"https://nickjanetakis.com/blog/docker-tip-32-automatically-clean-up-after-docker-daily",children:"prune your images and volumes on a recurring basis"}),"."]}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{src:"https://pagertree.com/assets/img/posts/2020/01/06/docker-system-df.png",alt:"Docker command cheat sheet System Off"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"docker system df Example Output"})})]}),"\n",(0,r.jsxs)(s.h2,{id:"prune-images-and-volumes-",children:["Prune Images and Volumes ",(0,r.jsx)("a",{href:"#prune-images-and-volumes",id:"prune-images-and-volumes"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Command: ",(0,r.jsx)(s.code,{children:"docker system prune -af"})]}),"\n",(0,r.jsx)(s.li,{children:"Description: Remove all unused images (dangling and unreferenced), containers, networks, and volumes."}),"\n",(0,r.jsxs)(s.li,{children:["Official Docs: ",(0,r.jsx)(s.a,{href:"https://docs.docker.com/engine/reference/commandline/system_prune/",children:"https://docs.docker.com/engine/reference/commandline/system_prune/"})]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"You\u2019ll probably only use this command on a Docker build machine or on your dev box, nevertheless take note, cause you are likely to use it."}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{src:"https://pagertree.com/assets/img/posts/2020/01/06/docker-system-prune-af.png",alt:"Docker command cheat sheet image prune"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"docker system prune -af Example Output"})})]}),"\n",(0,r.jsxs)(s.p,{children:["Also, just like mentioned above, if this is a build box consider setting up a cron job to prune your images. If you\u2019re a cron syntax noob like me, you might find ",(0,r.jsx)(s.a,{href:"https://crontab.guru/",children:"crontab.guru"})," of use in understanding the syntax and shortcuts for ",(0,r.jsx)(s.a,{href:"https://crontab.guru/examples.html",children:"popular time intervals"}),"."]}),"\n",(0,r.jsxs)("figure",{children:[(0,r.jsx)(s.img,{src:"https://pagertree.com/assets/img/posts/2020/01/06/crontab-l.png",alt:"Docker
1command cheat sheet crontab"}),(0,r.jsx)("figcaption",{children:(0,r.jsx)("p",{children:"crontab -l Example Output"})})]}),"\n",(0,r.jsxs)(s.h2,{id:"docker-links-you-might-find-useful-",children:["Docker Links You Might Find Useful ",(0,r.jsx)("a",{href:"#docker-links-you-might-find-useful",id:"docker-links-you-might-find-useful"})]}),"\n",(0,r.jsxs)(s.h3,{id:"images-",children:["Images ",(0,r.jsx)("a",{href:"#images",id:"images"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://github.com/hwdsl2/docker-ipsec-vpn-server",children:"VPN"})," - Run an IPsec VPN server. Super useful if you work from cafes like Starbucks."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://github.com/stefanprodan/dockprom",children:"Prometheus + Grafana Setup"})," - Out of the box Prometheus and Grafana setup. We actually use a fork of this for monitoring the ",(0,r.jsx)(s.a,{href:"https://pagertree.com/",children:"PagerTree"})," platform."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://hub.docker.com/_/alpine/",children:"Alpine Image"})," - Slim OS image for Node.js apps in production."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://docs.gitlab.com/runner/install/docker.html",children:"GitLab Runner"})," - A GitLab Runner inside a docker container. We use this at PagerTree to build our images."]}),"\n"]}),"\n",(0,r.jsxs)(s.h3,{id:"blog-articles-",children:["Blog Articles ",(0,r.jsx)("a",{href:"#blog-articles",id:"blog-articles"})]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://pagertree.com/learn/docker",children:"Learn Docker Series"})," - A quick and concise overview of all the peices of Docker you need to know."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://blog.sourcerer.io/a-crash-course-on-docker-learn-to-swim-with-the-big-fish-6ff25e8958b0",children:"Docker Crash Course"})," - If you\u2019re new to Docker this is a great crash course. Starts from installing Docker all the way to docker compose. It can be a lot to take in so you might have to read it a couple times."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://medium.com/@alfianeffendy/deployment-automation-with-gitlab-runner-aws-ecs-docker-c3007908f358",children:"Deployment Automation with GitLab Runner"})," - Super helpful writeup on setting up the GitLab Runner for your own CI/CD pipeline. Used this tutorial extensively when setting up PagerTree\u2019s CI/CD."]}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"pagertree-cheat-sheets",children:"PagerTree Cheat Sheets"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://pagertree.com/blog/promql-cheat-sheet-a-quick-guide-to-prometheus-query-language",children:"PromQL Cheat Sheet"})}),"\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://pagertree.com/blog/ruby-on-rails-cheat-sheet",children:"Ruby On Rails Cheat Sheet"})}),"\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.a,{href:"https://pagertree.com/blog/powershell-cheat-sheet-essential-commands-for-efficient-scripting",children:"PowerShell Cheat Sheet"})}),"\n"]}),"\n",(0,r.jsxs)(s.h3,{id:"cheat-sheets-pdfs-",children:["Cheat Sheets (PDFs) ",(0,r.jsx)("a",{href:"#cheat-sheets",id:"cheat-sheets"})]}),"\n",(0,r.jsx)(s.p,{children:'You can download this entire blog article with the "Export as PDF" link in the top right of this page (you might have to be on the desktop version. Additionally, below I\'ve provided some PDFs from the web I have found useful.'}),"\n",(0,r.jsx)(s.p,{children:(0,r.jsx)(s.a,{target:"_blank","data-noBrokenLinkCheck":!0,href:n(9181).A+"",children:"pagertree.com docker commands cheat sheet"})}),"\n",(0,r.jsx)(s.p,{children:(0,r.jsx)(s.a,{target:"_blank","data-noBrokenLinkCheck":!0,href:n(3630).A+"",children:"Official Docker Cheat Sheet"})}),"\n",(0,r.jsx)(s.p,{children:(0,r.jsx)(s.a,{target:"_blank","data-noBrokenLinkCheck":!0,href:n(729).A+"",children:"Red Hat Developer Docker Cheat Sheet"})}),"\n",(0,r.jsx)(s.p,{children:(0,r.jsx)(s.a,{target:"_blank","data-noBrokenLinkCheck":!0,href:n(4642).A+"",children:"Docker Cheat Sheet V2 by @dockerlux"})})]})}function h(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},3630:(e,s,n)=>{n.d(s,{A:()=>t});const t=n.p+"assets/files/docker_official_cheat_sheet-4889d2cc0b4fbd6e4308b491053c791a.pdf"},4642:(e,s,n)=>{n.d(s,{A:()=>t});
1const t=n.p+"assets/files/cheat-sheet-v2-e1a216d52409fd97c42e56514258ae6b.pdf"},8145:(e,s,n)=>{n.d(s,{A:()=>t});const t=n.p+"assets/images/docker-commands-cheat-sheet-47c1147f9afa1c31a3e7d89f7565fa81.png"},8453:(e,s,n)=>{n.d(s,{R:()=>o,x:()=>a});var t=n(6540);const r={},i=t.createContext(r);function o(e){const s=t.useContext(i);return t.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),t.createElement(i.Provider,{value:s},e.children)}},9181:(e,s,n)=>{n.d(s,{A:()=>t});const t=n.p+"assets/files/docker-commands-cheat-sheet-57164a8e9e1013fad241b93aa4ca6d73.pdf"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.