{"id":22829031,"url":"https://github.com/nikoo-asadnejad/docker-commands-cheat-sheet","last_synced_at":"2026-05-09T00:35:06.448Z","repository":{"id":265449183,"uuid":"860347162","full_name":"Nikoo-Asadnejad/Docker-Commands-Cheat-Sheet","owner":"Nikoo-Asadnejad","description":"This cheat sheet includes sections on getting started, managing images, containers, networking, volumes, Docker Compose, and Docker Swarm","archived":false,"fork":false,"pushed_at":"2025-01-02T14:21:27.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T06:38:40.026Z","etag":null,"topics":["docker","docker-cheatsheet","docker-cheetsheet","docker-command","docker-commands","docker-compose","docker-image","docker-learn","dockercommad","dockercommands"],"latest_commit_sha":null,"homepage":"","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/Nikoo-Asadnejad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2024-09-20T09:09:59.000Z","updated_at":"2025-01-06T18:20:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"092bc769-1575-4a4a-bfd7-08dec880e61d","html_url":"https://github.com/Nikoo-Asadnejad/Docker-Commands-Cheat-Sheet","commit_stats":null,"previous_names":["nikoo-asadnejad/docker-commands-cheat-sheet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FDocker-Commands-Cheat-Sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FDocker-Commands-Cheat-Sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FDocker-Commands-Cheat-Sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FDocker-Commands-Cheat-Sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nikoo-Asadnejad","download_url":"https://codeload.github.com/Nikoo-Asadnejad/Docker-Commands-Cheat-Sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246400108,"owners_count":20770957,"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":["docker","docker-cheatsheet","docker-cheetsheet","docker-command","docker-commands","docker-compose","docker-image","docker-learn","dockercommad","dockercommands"],"created_at":"2024-12-12T19:13:04.613Z","updated_at":"2026-05-09T00:35:06.439Z","avatar_url":"https://github.com/Nikoo-Asadnejad.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Command Cheat Sheet\n\nThis cheat sheet provides a quick reference for common Docker commands.\n\n## Table of Contents\n\n- [Getting Started](#getting-started)\n- [Images](#images)\n- [Containers](#containers)\n- [Networking](#networking)\n- [Volumes](#volumes)\n- [Inspection \u0026 Formatting](#inspection--formatting)\n- [Resource Monitoring](#resource-monitoring)\n- [Security](#security)\n- [Context \u0026 Remote Hosts](#context--remote-hosts)\n- [Buildx \u0026 Multi-Platform](#buildx--multi-platform)\n- [Registry \u0026 Login](#registry--login)\n- [Docker Compose](#docker-compose)\n- [Docker Swarm](#docker-swarm)\n\n## Getting Started\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker --version`                           | Display the installed Docker version                |\n| `docker info`                                | Display system-wide information about Docker        |\n| `docker help`                                | Display help for Docker commands                    |\n\n---\n\n## Images\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker pull \u003cimage\u003e`                        | Pull an image from Docker Hub                       |\n| `docker images`                              | List all available images                           |\n| `docker rmi \u003cimage\u003e`                         | Remove an image                                     |\n| `docker build -t \u003cimage-name\u003e:\u003ctag\u003e \u003cpath\u003e`| Build an image from a Dockerfile                    |\n| `docker tag \u003csource-image\u003e \u003ctarget-image\u003e`  | Tag an image with a new name                       |\n| `docker search \u003cterm\u003e`                       | Search for images on Docker Hub                     |\n| `docker history \u003cimage\u003e` | Show image layer history |\n| `docker save -o file.tar \u003cimage\u003e` | Save image to tar archive |\n| `docker load -i file.tar` | Load image from tar archive |\n| `docker image inspect \u003cimage\u003e` | Detailed image info |\n| `docker image prune -a` | Remove unused images |\n---\n\n## Containers\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker run \u003cimage\u003e`                         | Run a command in a new container                    |\n| `docker run -d \u003cimage\u003e`                      | Run a container in detached mode                    |\n| `docker run -d  --name \u003cname\u003e -p \u003cServerport\u003e:\u003ccontainerport\u003e \u003cimage\u003e`                      | Run a container in detached mode give it specific name and map the port of the container                   |\n| `docker run -tid --name \u003cname\u003e --memory 60mb -p 5050:80`                 | Run a container and specify memory for it    |\n| `docker run -tid \u003cimage\u003e sh`                 | Open shell of the container in current terminal     |\n| `docker ps` or `docker container ls`         | List running containers                             |\n| `docker ps -a` or `docker container ls -a`   | List all containers, including stopped ones         |\n| `docker stop \u003ccontainer\u003e`                    | Stop a running container                            |\n| `docker stop -60 \u003ccontainer\u003e`                | Stop a running container in 60 sec                  |\n| `docker container kill \u003ccontainer\u003e`          | Kill a running container                            |\n| `docker start \u003ccontainer\u003e`                   | Start a stopped container                           |\n| `docker restart \u003ccontainer\u003e`                 | Restart a container                                 |\n| `docker rm \u003ccontainer\u003e`                      | Remove a stopped container                          |\n| `docker rm \u003ccontainer\u003e --force`              | Remove a stopped container forcably                 |\n| `docker exec -it \u003ccontainer\u003e \u003ccommand\u003e`      | Execute a command inside a running container        |\n| `docker logs \u003ccontainer\u003e`                    | Fetch the logs of a container                       |\n| `docker attach \u003ccontainer\u003e` | Attach terminal to running container |\n| `docker pause \u003ccontainer\u003e` | Pause all processes |\n| `docker unpause \u003ccontainer\u003e` | Resume paused container |\n| `docker rename \u003cold\u003e \u003cnew\u003e` | Rename container |\n| `docker update --memory 200m \u003ccontainer\u003e` | Update container resources |\n| `docker wait \u003ccontainer\u003e` | Wait until container stops |\n---\n\n## Networking\n\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker network ls`                          | List all existing Docker networks. Displays details such as network name, ID, driver type, and scope. |\n| `docker network create \u003cnetwork-name\u003e`      | Create a new user-defined network with the specified name. By default, it uses the `bridge` driver. |\n| `docker network create --driver \u003cdriver-name\u003e \u003cnetwork-name\u003e` | Create a network using a specific driver (e.g., `bridge`, `overlay`, `host`, or `none`). |\n| `docker network rm \u003cnetwork-name\u003e`          | Remove a Docker network. The network must not be in use by any containers. |\n| `docker network inspect \u003cnetwork-name\u003e`     | Display detailed information about a network, including connected containers, IP ranges, and driver type. |\n| `docker run --network \u003cnetwork-name\u003e \u003cimage\u003e`| Start a container and connect it to a specific network at runtime. |\n| `docker network connect \u003cnetwork-name\u003e \u003ccontainer-id\u003e` | Connect an existing container to a specified network. |\n| `docker network disconnect \u003cnetwork-name\u003e \u003ccontainer-id\u003e` | Disconnect a container from a specific network. |\n| `docker network prune`                      | Remove all unused Docker networks. Be cautious as it deletes networks not being used by containers. |\n| `docker-compose up`                         | Automatically creates and manages a network for the services defined in the `docker-compose.yml` file. |\n| `docker network create --subnet=\u003cCIDR\u003e \u003cnetwork-name\u003e` | Create a network with a custom subnet (CIDR notation). |\n| `docker network create --gateway=\u003cIP\u003e \u003cnetwork-name\u003e` | Create a network with a custom gateway IP address. |\n| `docker network create -o com.docker.network.bridge.name=\u003cbridge-name\u003e \u003cnetwork-name\u003e` | Create a `bridge` network with a specific bridge name. |\n\n## Inspection \u0026 Formatting\n\n| Command | Description |\n|--------|-------------|\n| `docker inspect \u003cobject\u003e` | Low-level details (JSON) |\n| `docker inspect -f '{{.State.Status}}' \u003ccontainer\u003e` | Format output |\n| `docker ps --format \"table {{.Names}}\\t{{.Status}}\"` | Custom table output |\n\n---\n\n## Volumes\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker volume ls`                           | List all volumes                                    |\n| `docker volume create \u003cvolume-name\u003e`        | Create a new volume                                 |\n| `docker volume rm \u003cvolume-name\u003e`            | Remove a volume                                     |\n| `docker run -v \u003cvolume-name\u003e:\u003ccontainer-path\u003e \u003cimage\u003e`| Mount a volume into a container             |\n| `docker volume create --driver local --opt type=nfs  --opt o=addr=\u003cNFS_SERVER_IP\u003e,rw --opt device=:/export/shared  my-nfs-volume` | Create centrlized nfs sharing volume |\n\n---\n\n## Resource Monitoring\n\n| Command | Description |\n|--------|-------------|\n| `docker stats` | Live resource usage of containers |\n| `docker top \u003ccontainer\u003e` | Running processes in container |\n| `docker events` | Real-time Docker events |\n\n---\n\n## Security\n\n| Command | Description |\n|--------|-------------|\n| `docker scan \u003cimage\u003e` | Scan image for vulnerabilities |\n| `docker trust inspect \u003cimage\u003e` | Verify image signatures |\n\n---\n\n## Registry \u0026 Login\n\n| Command | Description |\n|--------|-------------|\n| `docker login` | Login to registry |\n| `docker logout` | Logout |\n| `docker push \u003cimage\u003e` | Push image to registry |\n| `docker pull \u003cimage\u003e` | Pull image |\n\n---\n\n## Context \u0026 Remote Hosts\n\n| Command | Description |\n|--------|-------------|\n| `docker context ls` | List contexts |\n| `docker context create \u003cname\u003e` | Create new context |\n| `docker context use \u003cname\u003e` | Switch context |\n\n---\n\n## Buildx \u0026 Multi-Platform\n\n| Command | Description |\n|--------|-------------|\n| `docker buildx ls` | List builders |\n| `docker buildx create` | Create builder |\n| `docker buildx build --platform linux/amd64,linux/arm64 .` | Multi-arch build |\n| `docker buildx bake` | Build from config |\n\n---\n\n## Docker Compose\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker-compose up`                          | Start all services defined in a `docker-compose.yml` file. Creates and starts containers as needed. |\n| `docker-compose up -d`                       | Start services in detached mode (running in the background). |\n| `docker-compose down`                        | Stop and remove containers, networks, volumes, and images created by `docker-compose up`. |\n| `docker-compose down -v`                     | Stop and remove services along with their associated volumes. |\n| `docker-compose ps`                          | List the status of containers for the services defined in the `docker-compose.yml` file. |\n| `docker-compose logs`                        | View logs for all running services. By default, it displays real-time logs. |\n| `docker-compose logs -f`                     | Follow logs in real-time for services defined in the `docker-compose.yml` file. |\n| `docker-compose build`                       | Build or rebuild images for services defined in the `docker-compose.yml` file. |\n| `docker-compose build --no-cache`            | Build services without using the cache. Forces a fresh build. |\n| `docker-compose pull`                        | Pull the latest images for all services defined in the `docker-compose.yml` file. |\n| `docker-compose start`                       | Start containers for services that were stopped but not removed. |\n| `docker-compose stop`                        | Stop running containers without removing them. They can be restarted later using `docker-compose start`. |\n| `docker-compose restart`                     | Restart running containers for services defined in the `docker-compose.yml` file. |\n| `docker-compose exec \u003cservice-name\u003e \u003ccommand\u003e` | Execute a command inside a running service container. |\n| `docker-compose run \u003cservice-name\u003e \u003ccommand\u003e` | Run a one-off command in a new container for a service. |\n| `docker-compose config`                      | Validate and view the configuration of the `docker-compose.yml` file. |\n| `docker-compose config --services`           | List all services defined in the `docker-compose.yml` file. |\n| `docker-compose config --volumes`            | List all volumes defined in the `docker-compose.yml` file. |\n| `docker-compose kill`                        | Forcefully stop running containers for all services. |\n| `docker-compose rm`                          | Remove stopped service containers. Prompts for confirmation by default. |\n| `docker-compose rm -f`                       | Remove stopped service containers without confirmation. |\n| `docker-compose version`                     | Display the installed version of Docker Compose. |\n\n---\n\n## Docker Swarm\n\n| Command                                      | Description                                         |\n|----------------------------------------------|-----------------------------------------------------|\n| `docker swarm init`                          | Initialize a new Swarm and make the current node the Swarm manager. |\n| `docker swarm join --token \u003ctoken\u003e \u003cmanager-ip\u003e:\u003cport\u003e` | Join a Swarm as a worker node using the provided token and manager IP. |\n| `docker swarm join-token manager`           | Display the join token command to add another manager node. |\n| `docker swarm join-token worker`            | Display the join token command to add a worker node. |\n| `docker swarm leave`                        | Leave the Swarm. Use `--force` if the node is a manager. |\n| `docker service create --name \u003cservice-name\u003e \u003cimage\u003e` | Create a new service in the Swarm using the specified image. |\n| `docker service update \u003cservice-name\u003e --image \u003cnew-image\u003e` | Update an existing service to use a new image. |\n| `docker service ls`                          | List all services running in the Swarm. |\n| `docker service ps \u003cservice-name\u003e`           | List all tasks (containers) of a specific service. |\n| `docker service logs \u003cservice-name\u003e`         | View logs for a specific service. |\n| `docker service rm \u003cservice-name\u003e`           | Remove a service from the Swarm. |\n| `docker service scale \u003cservice-name\u003e=\u003creplica-count\u003e` | Scale a service to the specified number of replicas. |\n| `docker node ls`                             | List all nodes in the Swarm, showing their roles, availability, and status. |\n| `docker node ps \u003cnode-id\u003e`                   | List tasks running on a specific node. |\n| `docker node rm \u003cnode-id\u003e`                   | Remove a node from the Swarm. The node must leave the Swarm first. |\n| `docker node update --availability \u003cactive|pause|drain\u003e \u003cnode-id\u003e` | Change the availability state of a node. |\n| `docker stack deploy -c \u003ccompose-file.yml\u003e \u003cstack-name\u003e` | Deploy a stack using a Docker Compose file. |\n| `docker stack ls`                            | List all deployed stacks in the Swarm. |\n| `docker stack ps \u003cstack-name\u003e`               | List all tasks in a stack. |\n| `docker stack rm \u003cstack-name\u003e`               | Remove a deployed stack. |\n| `docker inspect \u003cobject\u003e`                    | Inspect the details of any Docker object (node, service, task, etc.). |\n| `docker events`                              | Display real-time events from the Swarm. |\n| `docker swarm update --task-history-limit \u003cvalue\u003e` | Update Swarm settings, such as task history limit. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikoo-asadnejad%2Fdocker-commands-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikoo-asadnejad%2Fdocker-commands-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikoo-asadnejad%2Fdocker-commands-cheat-sheet/lists"}