Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nikoo-asadnejad/docker-commands-cheat-sheet

This cheat sheet includes sections on getting started, managing images, containers, networking, volumes, Docker Compose, and Docker Swarm
https://github.com/nikoo-asadnejad/docker-commands-cheat-sheet

docker docker-cheatsheet docker-cheetsheet docker-command docker-commands docker-compose docker-image docker-learn dockercommad dockercommands

Last synced: 6 days ago
JSON representation

This cheat sheet includes sections on getting started, managing images, containers, networking, volumes, Docker Compose, and Docker Swarm

Awesome Lists containing this project

README

        

# Docker Command Cheat Sheet

This cheat sheet provides a quick reference for common Docker commands.

## Table of Contents

- [Getting Started](#getting-started)
- [Images](#images)
- [Containers](#containers)
- [Networking](#networking)
- [Volumes](#volumes)
- [Docker Compose](#docker-compose)
- [Docker Swarm](#docker-swarm)

## Getting Started

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker --version` | Display the installed Docker version |
| `docker info` | Display system-wide information about Docker |
| `docker help` | Display help for Docker commands |

---

## Images

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker pull ` | Pull an image from Docker Hub |
| `docker images` | List all available images |
| `docker rmi ` | Remove an image |
| `docker build -t : `| Build an image from a Dockerfile |
| `docker tag ` | Tag an image with a new name |
| `docker search ` | Search for images on Docker Hub |

---

## Containers

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker run ` | Run a command in a new container |
| `docker run -d ` | Run a container in detached mode |
| `docker run -d --name -p : ` | Run a container in detached mode give it specific name and map the port of the container |
| `docker run -tid --name --memory 60mb -p 5050:80` | Run a container and specify memory for it |
| `docker run -tid sh` | Open shell of the container in current terminal |
| `docker ps` or `docker container ls` | List running containers |
| `docker ps -a` or `docker container ls -a` | List all containers, including stopped ones |
| `docker stop ` | Stop a running container |
| `docker stop -60 ` | Stop a running container in 60 sec |
| `docker container kill ` | Kill a running container |
| `docker start ` | Start a stopped container |
| `docker restart ` | Restart a container |
| `docker rm ` | Remove a stopped container |
| `docker rm --force` | Remove a stopped container forcably |
| `docker exec -it ` | Execute a command inside a running container |
| `docker logs ` | Fetch the logs of a container |

---

## Networking

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker network ls` | List all existing Docker networks. Displays details such as network name, ID, driver type, and scope. |
| `docker network create ` | Create a new user-defined network with the specified name. By default, it uses the `bridge` driver. |
| `docker network create --driver ` | Create a network using a specific driver (e.g., `bridge`, `overlay`, `host`, or `none`). |
| `docker network rm ` | Remove a Docker network. The network must not be in use by any containers. |
| `docker network inspect ` | Display detailed information about a network, including connected containers, IP ranges, and driver type. |
| `docker run --network `| Start a container and connect it to a specific network at runtime. |
| `docker network connect ` | Connect an existing container to a specified network. |
| `docker network disconnect ` | Disconnect a container from a specific network. |
| `docker network prune` | Remove all unused Docker networks. Be cautious as it deletes networks not being used by containers. |
| `docker-compose up` | Automatically creates and manages a network for the services defined in the `docker-compose.yml` file. |
| `docker network create --subnet= ` | Create a network with a custom subnet (CIDR notation). |
| `docker network create --gateway= ` | Create a network with a custom gateway IP address. |
| `docker network create -o com.docker.network.bridge.name= ` | Create a `bridge` network with a specific bridge name. |

---

## Volumes

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker volume ls` | List all volumes |
| `docker volume create ` | Create a new volume |
| `docker volume rm ` | Remove a volume |
| `docker run -v : `| Mount a volume into a container |
| `docker volume create --driver local --opt type=nfs --opt o=addr=,rw --opt device=:/export/shared my-nfs-volume` | Create centrlized nfs sharing volume |

---

## Docker Compose

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker-compose up` | Start all services defined in a `docker-compose.yml` file. Creates and starts containers as needed. |
| `docker-compose up -d` | Start services in detached mode (running in the background). |
| `docker-compose down` | Stop and remove containers, networks, volumes, and images created by `docker-compose up`. |
| `docker-compose down -v` | Stop and remove services along with their associated volumes. |
| `docker-compose ps` | List the status of containers for the services defined in the `docker-compose.yml` file. |
| `docker-compose logs` | View logs for all running services. By default, it displays real-time logs. |
| `docker-compose logs -f` | Follow logs in real-time for services defined in the `docker-compose.yml` file. |
| `docker-compose build` | Build or rebuild images for services defined in the `docker-compose.yml` file. |
| `docker-compose build --no-cache` | Build services without using the cache. Forces a fresh build. |
| `docker-compose pull` | Pull the latest images for all services defined in the `docker-compose.yml` file. |
| `docker-compose start` | Start containers for services that were stopped but not removed. |
| `docker-compose stop` | Stop running containers without removing them. They can be restarted later using `docker-compose start`. |
| `docker-compose restart` | Restart running containers for services defined in the `docker-compose.yml` file. |
| `docker-compose exec ` | Execute a command inside a running service container. |
| `docker-compose run ` | Run a one-off command in a new container for a service. |
| `docker-compose config` | Validate and view the configuration of the `docker-compose.yml` file. |
| `docker-compose config --services` | List all services defined in the `docker-compose.yml` file. |
| `docker-compose config --volumes` | List all volumes defined in the `docker-compose.yml` file. |
| `docker-compose kill` | Forcefully stop running containers for all services. |
| `docker-compose rm` | Remove stopped service containers. Prompts for confirmation by default. |
| `docker-compose rm -f` | Remove stopped service containers without confirmation. |
| `docker-compose version` | Display the installed version of Docker Compose. |

---

## Docker Swarm

| Command | Description |
|----------------------------------------------|-----------------------------------------------------|
| `docker swarm init` | Initialize a new Swarm and make the current node the Swarm manager. |
| `docker swarm join --token :` | Join a Swarm as a worker node using the provided token and manager IP. |
| `docker swarm join-token manager` | Display the join token command to add another manager node. |
| `docker swarm join-token worker` | Display the join token command to add a worker node. |
| `docker swarm leave` | Leave the Swarm. Use `--force` if the node is a manager. |
| `docker service create --name ` | Create a new service in the Swarm using the specified image. |
| `docker service update --image ` | Update an existing service to use a new image. |
| `docker service ls` | List all services running in the Swarm. |
| `docker service ps ` | List all tasks (containers) of a specific service. |
| `docker service logs ` | View logs for a specific service. |
| `docker service rm ` | Remove a service from the Swarm. |
| `docker service scale =` | Scale a service to the specified number of replicas. |
| `docker node ls` | List all nodes in the Swarm, showing their roles, availability, and status. |
| `docker node ps ` | List tasks running on a specific node. |
| `docker node rm ` | Remove a node from the Swarm. The node must leave the Swarm first. |
| `docker node update --availability ` | Change the availability state of a node. |
| `docker stack deploy -c ` | Deploy a stack using a Docker Compose file. |
| `docker stack ls` | List all deployed stacks in the Swarm. |
| `docker stack ps ` | List all tasks in a stack. |
| `docker stack rm ` | Remove a deployed stack. |
| `docker inspect ` | Inspect the details of any Docker object (node, service, task, etc.). |
| `docker events` | Display real-time events from the Swarm. |
| `docker swarm update --task-history-limit ` | Update Swarm settings, such as task history limit. |