{"id":15127512,"url":"https://github.com/sudheerj/docker-cheat-sheet","last_synced_at":"2026-03-06T05:04:56.578Z","repository":{"id":41811919,"uuid":"193906482","full_name":"sudheerj/docker-cheat-sheet","owner":"sudheerj","description":"Quick reference guide for Docker commands","archived":false,"fork":false,"pushed_at":"2024-09-18T11:57:06.000Z","size":91,"stargazers_count":215,"open_issues_count":0,"forks_count":135,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-11T10:33:10.996Z","etag":null,"topics":["cheatsheet","docker","docker-commands","docker-container"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudheerj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["sudheerj"],"custom":"https://buymeacoffee.com/sudheerj"}},"created_at":"2019-06-26T13:08:40.000Z","updated_at":"2025-01-08T10:34:57.000Z","dependencies_parsed_at":"2024-09-20T18:10:43.189Z","dependency_job_id":"89ebeff4-9675-45f9-8a62-9981f4e7e8fc","html_url":"https://github.com/sudheerj/docker-cheat-sheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2Fdocker-cheat-sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2Fdocker-cheat-sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2Fdocker-cheat-sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2Fdocker-cheat-sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudheerj","download_url":"https://codeload.github.com/sudheerj/docker-cheat-sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241198705,"owners_count":19926502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheatsheet","docker","docker-commands","docker-container"],"created_at":"2024-09-26T02:04:46.984Z","updated_at":"2026-03-06T05:04:56.540Z","avatar_url":"https://github.com/sudheerj.png","language":null,"funding_links":["https://github.com/sponsors/sudheerj","https://buymeacoffee.com/sudheerj"],"categories":[],"sub_categories":[],"readme":"# docker-cheat-sheet\nQuick reference guide for Docker commands\n\u003e Click :star:if you like the project. Pull Requests are highly appreciated. Follow me [@SudheerJonna](https://twitter.com/SudheerJonna) for technical updates.\n\n## Downloading PDF/Epub formats\n\nYou can download the PDF and Epub version of this repository from the latest run on the [actions tab](https://github.com/sudheerj/docker-cheat-sheet/actions).\n\n### Table of Contents\n\n| No. | Questions |\n|---- | ---------\n|1  | [**What is docker?**](#what-is-docker) |\n|2  | [**Why docker?**](#why-docker)|\n|3  | [**Installation**](#installation) |\n|4  | [**Registries and Repositories**](#registries-and-repositories)|\n|5  | [**Create,Run,Update and Delete containers**](#)|\n|6  | [**Start and stop containers**](#start-and-stop-containers) |\n|7  | [**Networks**](#networks)|\n|8  | [**Cleanup commands**](#cleanup-commands)|\n|9  | [**Utility commands**](#utility-commands)|\n|10 | [**Docker Hub**](#docker-hub)|\n|11 | [**Dockerfile**](#dockerfile)|\n|12 | [**Docker Compose**](#docker-compose)|\n|13 | [**Docker Swarm**](#docker-swarm)|\n\n### What is docker?\n   Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.\n\n   **[⬆ Back to Top](#table-of-contents)**\n\n### Why docker?\n   Docker is useful to automate the deployment of applications inside a software containers, which makes the applications easy to ship and run virtually anywhere (i.e, platform independent). The Docker container processes run on the host kernel, unlike VM which runs processes in guest kernel.\n\n   ![dockervsvm](images/dockervsvm.jpg)\n\n   **[⬆ Back to Top](#table-of-contents)**\n\n### Installation\nThe docker desktop downloads are available for windows, mac and linux distributions.\n\n#### Windows\nIt supports for Windows 10 64-bit: Home, Pro, Enterprise, or Education, version 1903 (Build 18362 or higher). You need to follow the below steps for installation.\n\n1. Download docker desktop for windows from https://docs.docker.com/docker-for-windows/install/\n2. Double-click `Docker Desktop Installer.exe` to run the installer.\n3. Make sure `Enable Hyper-V Windows Features` option is selected\n\n#### Mac\n\n1. Download docker desktop for mac from https://docs.docker.com/docker-for-mac/install/\n2. Double-click `Docker.dmg` to open the installer and drag it to the Applications folder.\n3. Double-click `Docker.app` in the Applications folder to start Docker.\n\n#### Linux\n\nYou can install from a package easily\n1. Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version and then go to pool/stable/ to get .deb file\n2. Install Docker Engine by referring the downloaded location of the Docker package.\n```cmd\n$ sudo dpkg -i /path/to/package.deb\n```\n3. Verify the Docker Engine by running the `hello-world` image to check correct installation.\n```cmd\n$ sudo docker run hello-world\n```\n\n   **[⬆ Back to Top](#table-of-contents)**\n\n### Registries and Repositories\n#### Registry:\nDocker Registry is a service that stores your docker images. It could be hosted by a third party, as public or private registry. Some of the examples are,\n\n- Docker Hub,\n- Quay,\n- Google Container Registry,\n- AWS Container Registry\n\n#### Repository:\nA Docker Repository is a collection of related images with same name which have different tags. These tags are an alphanumeric identifiers(like 1.0 or latest) attached to images within a repository.\n\nFor example, if you want to pull golang image using `docker pull golang:latest` command, it will download the image tagged latest within the `golang` repository from the Docker Hub registry. The tags appeared on dockerhub as below,\n\n#### Login\nLogin to a registry\n```js\n\u003e docker login [OPTIONS] [SERVER]\n\n[OPTIONS]:\n-u/--username username\n-p/--password password\n\nExample:\n\n1. docker login localhost:8080 // Login to a registry on your localhost\n2. docker login\n```\n\n#### Logout\nLogout from a registry\n```js\n\u003e docker logout [SERVER]\n\nExample:\n\ndocker logout localhost:8080 // Logout from a registry on your localhost\n```\n\n#### Search image\nSearch for an image in registry\n```js\ndocker search [OPTIONS] TERM\n\nExample:\ndocker search golang\ndocker search --filter stars=3 --no-trunc golang\n```\n#### Pull image\n\nThis command pulls an image or a repository from a registry to local machine\n\n```js\ndocker image pull [OPTIONS] NAME[:TAG|@DIGEST]\n\nExample:\ndocker image pull golang:latest\n```\n#### Push image\n\nThis command pushes an image to the registry from local machine.\n\n```js\ndocker image push [OPTIONS] NAME[:TAG]\ndocker image push golang:latest\n```\n\n  **[⬆ Back to Top](#table-of-contents)**\n\n### Create,Run,Update and Delete containers\n\n#### Create\nCreate a new container\n```cmd\ndocker container create [OPTIONS] IMAGE [COMMAND] [ARG...]\n\nExample:\ndocker container create -t -i sudheerj/golang --name golang\n```\n\n#### Rename\n\nRename a container\n\n```cmd\ndocker container rename CONTAINER NEW_NAME\n\nExample:\ndocker container rename golang golanguage\ndocker container rename golanguage golang\n```\n\n#### Run\n\n```cmd\ndocker container run [OPTIONS] IMAGE [COMMAND] [ARG...]\n\nExample:\ndocker container run -it --name golang -d sudheerj/golang\n```\n\nYou can also run a command inside container\n```cmd\ndocker exec [OPTIONS] CONTAINER COMMAND [ARG...]\n\nExample:\ndocker exec -it golang sh // Or use bash command if sh is failed\n```\n\n#### Update\nUpdate configuration of one or more containers\n\n```cmd\ndocker container update [OPTIONS] CONTAINER [CONTAINER...]\n\nExample:\ndocker container update --memory \"1g\" --cpuset-cpu \"1\" golang // update the golang to use 1g of memory and only use cpu core 1\n```\n\n#### Remove\nRemove one or more containers\n\n```cmd\ndocker container rm [OPTIONS] CONTAINER [CONTAINER...]\n\nExample:\ndocker container rm golang\ndocker rm $(docker ps -q -f status=exited) // Remove all the stopped containers\n```\n  **[⬆ Back to Top](#table-of-contents)**\n### Start and stop containers\n\n#### Start\nStart one or more stopped containers\n\n```cmd\ndocker container start [OPTIONS] CONTAINER [CONTAINER...]\n\nExample:\ndocker container start golang\n```\n\n### Stop\nStop one or more running containers\n\n\n```cmd\ndocker container stop [OPTIONS] CONTAINER [CONTAINER...]\n\nExample:\ndocker container stop golang\ndocker stop $(docker ps -a -q) // To stop all the containers\n```\n\n#### Restart\nRestart one or more containers and processes running inside the container/containers.\n\n```cmd\ndocker container restart [OPTIONS] CONTAINER [CONTAINER...]\n\nExample:\ndocker container restart golang\n```\n\n#### Pause\nPause all processes within one or more containers\n\n```cmd\ndocker container pause CONTAINER [CONTAINER...]\n\nExample:\ndocker container pause golang\n```\n\n### Unpause/Resume\nUnpause all processes within one or more containers\n\n```cmd\ndocker container unpause CONTAINER [CONTAINER...]\n\nExample:\ndocker container unpause golang\n```\n\n#### Kill\nKill one or more running containers\n\n```cmd\ndocker container kill [OPTIONS] CONTAINER [CONTAINER...]\n\nExample:\ndocker container kill golang\n```\n\n#### Wait\nBlock until one or more containers stop and print their exit codes after that\n\n\n```cmd\ndocker container wait CONTAINER [CONTAINER...]\n\nExample:\ndocker container wait golang\n```\n  **[⬆ Back to Top](#table-of-contents)**\n\n### Networks\n   Docker provides network commands connect containers to each other and to other non-Docker workloads. The usage of network commands would be `docker network COMMAND`\n\n#### List networks\nList down available networks\n\n```cmd\ndocker network ls\n```\n\n#### Connect a container to network\nYou can connect a container by name or by ID to any network. Once it connected, the container can communicate with other containers in the same network.\n\n```cmd\ndocker network connect [OPTIONS] NETWORK CONTAINER\n\nExample:\ndocker network connect multi-host-network container1\n```\n\n#### Disconnect a container from a network\nYou can disconnect a container by name or by ID from any network.\n\n```cmd\ndocker network disconnect [OPTIONS] NETWORK CONTAINER\n\nExample:\ndocker network disconnect multi-host-network container1\n```\n\n#### Remove one or more networks\nRemoves one or more networks by name or identifier. Remember, you must first disconnect any containers connected to it before removing it.\n\n```cmd\ndocker network rm NETWORK [NETWORK...]\n\nExample:\ndocker network rm my-network\n```\n\n#### Create network\nIt is possible to create a network in Docker before launching containers\n\n```cmd\ndocker network create [OPTIONS] NETWORK\n\nExample:\nsudo docker network create –-driver bridge some_network\n```\n\nThe above command will output the long ID for the new network.\n\n#### Inspect network\nYou can see more details on the network associated with Docker using network inspect command.\n\n```cmd\ndocker network inspect networkname\n\nExample:\ndocker network inspect bridge\n```\n### Cleanup commands\n\nYou may need to cleanup resources (containers, volumes, images, networks) regularly.\n\n#### Remove all unused resources\n\n```cmd\ndocker system prune\n```\n\n#### Images\n\n```cmd\n$ docker images\n$ docker rmi $(docker images --filter \"dangling=true\" -q --no-trunc)\n\n$ docker images | grep \"none\"\n$ docker rmi $(docker images | grep \"none\" | awk '/ / { print $3 }')\n```\n\n#### Containers\n\n```cmd\n$ docker ps\n$ docker ps -a\n$ docker rm $(docker ps -qa --no-trunc --filter \"status=exited\")\n```\n\n#### Volumes\n\n```cmd\n$ docker volume rm $(docker volume ls -qf dangling=true)\n$ docker volume ls -qf dangling=true | xargs -r docker volume rm\n```\n\n#### Networks\n\n```cmd\n$ docker network ls\n$ docker network ls | grep \"bridge\"\n$ docker network rm $(docker network ls | grep \"bridge\" | awk '/ / { print $1 }')\n```\n\n  **[⬆ Back to Top](#table-of-contents)**\n\n### Utility commands\n\n  **[⬆ Back to Top](#table-of-contents)**\n\n### Docker Hub\n   Docker Hub is a cloud-based repository provided by Docker to test, store and distribute container images which can be accessed either privately or publicly.\n\n#### From\n   It initializes a new image and sets the Base Image for subsequent instructions. It must be a first non-comment instruction in the Dockerfile.\n   ```cmd\n   FROM \u003cimage\u003e\n   FROM \u003cimage\u003e:\u003ctag\u003e\n   FROM \u003cimage\u003e@\u003cdigest\u003e\n   ```\n   **Note:** Both `tag` and `digest` are optional. If you omit either of them, the builder assumes a latest by default.\n\n### Dockerfile\n   Dockerfile is a text document that contains set of commands and instructions which will be executed in a sequence in the docker environment for building a new docker image.\n\n#### FROM\nThis command Sets the Base Image for subsequent instructions\n\n```cmd\nFROM \u003cimage\u003e\nFROM \u003cimage\u003e:\u003ctag\u003e\nFROM \u003cimage\u003e@\u003cdigest\u003e\n\nExample:\nFROM ubuntu:18.04\n```\n\n#### RUN\n\nRUN instruction allows you to install your application and packages required for it. It executes any commands on top of the current image and creates a new layer by committing the results. It is quite common to have multiple RUN instructions in a Dockerfile.\n\nIt has two forms\n1. Shell Form: RUN \u003ccommand\u003e\n```cmd\nRUN npm start\n```\n2. Exec form RUN [\"\u003cexecutable\u003e\", \"\u003cparam1\u003e\", \"\u003cparam2\u003e\"]\n```cmd\nRUN [ \"npm\", \"start\" ]\n```\n\n#### ENTRYPOINT\nAn ENTRYPOINT allows you to configure a container that will run as an executable. It is used to run when container starts.\n\n```cmd\nExec Form:\nENTRYPOINT [\"executable\", \"param1\", \"param2\"]\nShell Form:\nENTRYPOINT command param1 param2\n\nExample:\nFROM alpine:3.5\nENTRYPOINT [\"/bin/echo\", \"Print ENTRYPOINT instruction of Exec Form\"]\n\n```\n\nIf an image has an ENTRYPOINT and pass an argument to it while running the container, it wont override the existing entrypoint but it just appends what you passed with the entrypoint. To override the existing ENTRYPOINT. you should user `–entrypoint` flag for the running container.\n\nLet's see the behavior with the above dockerfile,\n\n```cmd\nBuild image:\ndocker build -t entrypointImage .\n\nRun the image:\ndocker container run entrypointImage // Print ENTRYPOINT instruction of Exec Form\n\nOverride entrypoint:\ndocker run --entrypoint \"/bin/echo\" entrypointImage \"Override ENTRYPOINT instruction\" // Override ENTRYPOINT instruction\n```\n\n#### CMD\nCMD instruction is used to set a default command, which will be executed only when you run a container without specifying a command. But if the docker container runs with a command, the default command will be ignored.\n\nThe CMD instruction has three forms,\n```cmd\n1. Exec form:\nCMD [\"executable\",\"param1\",\"param2\"]\n2. Default params to ENTRYPOINT:\nCMD [\"param1\",\"param2\"]\n3. Shell form:\nCMD command param1 param2\n```\n\nThe main purpose of the CMD command is to launch the required software in a container. For example, running an executable .exe file or a Bash terminal as soon as the container starts.\n\nRemember, if docker runs with executable and parameters then CMD instruction will be overridden(Unlike ENTRYPOINT).\n\n```cmd\ndocker run executable parameters\n```\n\n**Note:** There should only be one CMD command in your Dockerfile. Otherwise only the last instance of CMD will be executed.\n\n#### COPY\nThe COPY instruction copies new files or directories from source and adds them to the destination filesystem of the container.\n\n```cmd\nCOPY [--chown=\u003cuser\u003e:\u003cgroup\u003e] \u003csrc\u003e... \u003cdest\u003e\nCOPY [--chown=\u003cuser\u003e:\u003cgroup\u003e] [\"\u003csrc\u003e\",... \"\u003cdest\u003e\"]\n\nExample:\nCOPY test.txt /absoluteDir/\nCOPY tes? /absoluteDir/ // Copies all files or directories starting with test to destination container\n```\n\nThe \u003csrc\u003e path must be relative to the source directory that is being built. Whereas \u003cdest\u003e is an absolute path, or a path relative to `WORKDIR`.\n#### ADD\nThe ADD instruction copies new files, directories or remote file URLs from source and adds them to the filesystem of the image at the destination path. The functionality is similar to COPY command and supports two forms of usage,\n\n```cmd\nADD [--chown=\u003cuser\u003e:\u003cgroup\u003e] \u003csrc\u003e... \u003cdest\u003e\nADD [--chown=\u003cuser\u003e:\u003cgroup\u003e] [\"\u003csrc\u003e\",... \"\u003cdest\u003e\"]\n\nExample:\nADD test.txt /absoluteDir/\nADD tes? /absoluteDir/ // Copies all files or directories starting with test to destination container\n```\n\nADD commands provides additional features such as downloading remote resources, extracting TAR files etc.\n\n```cmd\n1. Download an external file and copy to the destination\nADD http://source.file/url  /destination/path\n\n2. Copies compressed files and extract the content in the destination\nADD source.file.tar.gz /temp\n```\n\n#### ENV\nThe ENV instruction sets the environment variable \u003ckey\u003e to the value \u003cvalue\u003e. It has two forms,\n\n1. The first form, `ENV \u003ckey\u003e \u003cvalue\u003e`, will set a single variable to a value.\n2. The second form, `ENV \u003ckey\u003e=\u003cvalue\u003e ...`, allows for multiple variables to be set at one time.\n\n```cmd\nENV \u003ckey\u003e \u003cvalue\u003e\nENV \u003ckey\u003e=\u003cvalue\u003e [\u003ckey\u003e=\u003cvalue\u003e ...]\n\nExample:\nENV name=\"John Doe\" age=40\nENV name John Doe\nENV age 40\n```\n\n#### EXPOSE\nThe EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. i.e, It helps in inter-container communication. You can specify whether the port listens on TCP or UDP, and the default is TCP.\n\n```cmd\nEXPOSE \u003cport\u003e [\u003cport\u003e/\u003cprotocol\u003e...]\n\nExample:\nEXPOSE 80/udp\nEXPOSE 80/tcp\n```\n\nBut if you want to bind the port of the container with the host machine on which the container is running, use -p option of `docker run` command.\n\n```cmd\ndocker run -p \u003cHOST_PORT\u003e:\u003cCONTAINER:PORT\u003e IMAGE_NAME\n\nExample:\ndocker run -p 80:80/udp myDocker\n```\n\n#### WORKDIR\nThe WORKDIR command is used to define the working directory of a Docker container at any given time for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.\n\n```cmd\nWORKDIR /path/to/workdir\n\nExample:\nWORKDIR /c\nWORKDIR d\nWORKDIR e\nRUN pwd  // /c/d/e\n```\n\n#### LABEL\nThe LABEL instruction adds metadata as key-value pairs to an image. Labels included in base or parent images (images in the FROM line) are inherited by your image.\n\n```cmd\nLABEL \u003ckey\u003e=\u003cvalue\u003e \u003ckey\u003e=\u003cvalue\u003e \u003ckey\u003e=\u003cvalue\u003e ...\n\nExample:\nLABEL version=\"1.0\"\nLABEL multi.label1=\"value1\" \\\n      multi.label2=\"value2\" \\\n      other=\"value3\"\n```\n\nYou can view an image’s labels using the `docker image inspect --format='' myimage` command. The output would be as below,\n\n```js\n{\n  \"version\": \"1.0\",\n  \"multi.label1\": \"value1\",\n  \"multi.label2\": \"value2\",\n  \"other\": \"value3\"\n}\n```\n\n#### MAINTAINER\nThe MAINTAINER instruction sets the Author field of the generated images.\n```cmd\nMAINTAINER \u003cname\u003e\n\nExample:\nMAINTAINER John\n```\n\nThis command is deprecated status now and the recommended usage is with LABEL command\n```cmd\nLABEL maintainer=\"John\"\n```\n\n#### VOLUME\nThe VOLUME instruction creates a mount point with the specified name and mounted volumes from native host or other containers.\n\n```cmd\nVOLUME [\"/data\"]\n\nExample:\nFROM ubuntu\nRUN mkdir /test\nVOLUME /test\n```\n\n### Docker Compose\n   Docker compose(or compose) is a tool for defining and running multi-container Docker applications.\n### Docker Swarm\n   Docker Swarm(or swarm) is an open-source tool used to cluster and orchestrate Docker containers.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudheerj%2Fdocker-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudheerj%2Fdocker-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudheerj%2Fdocker-cheat-sheet/lists"}