2022-03-19 14:19:55 +01:00
|
|
|
|
---
|
2024-02-13 22:37:17 +01:00
|
|
|
|
title: Docker & Compose Cheat Sheet
|
2023-01-15 18:05:39 +01:00
|
|
|
|
description: This is my list of use full Docker commands.
|
2022-03-19 14:19:55 +01:00
|
|
|
|
date: 2020-12-02T00:00:00.000Z
|
2024-02-13 22:37:17 +01:00
|
|
|
|
lastmod: 2024-02-13T21:23:00.829Z
|
2022-03-19 14:19:55 +01:00
|
|
|
|
image: /images/blog/Image-Docker-Command-Cheat-Sheet.png
|
|
|
|
|
tags:
|
2023-01-15 18:06:12 +01:00
|
|
|
|
- Cheat-Sheet
|
|
|
|
|
- Command-Line
|
2024-02-13 22:37:17 +01:00
|
|
|
|
- Docker
|
2023-01-15 18:06:12 +01:00
|
|
|
|
- Linux
|
2024-02-13 22:37:17 +01:00
|
|
|
|
slug: docker-compose-cheat-sheet
|
2022-03-19 14:19:55 +01:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# A list of docker commands
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
### List images
|
|
|
|
|
|
2023-01-15 18:17:59 +01:00
|
|
|
|
```Shell
|
2022-03-19 14:19:55 +01:00
|
|
|
|
docker images [OPTIONS] [REPOSITORY[:TAG]]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Options
|
|
|
|
|
|
2023-01-15 18:19:48 +01:00
|
|
|
|
| Name, shorthand | Default | Description |
|
|
|
|
|
| :-------------- | :------: | --------------------------------------------------- |
|
|
|
|
|
| `--all, -a` | | Show all images (default hides intermediate images) |
|
|
|
|
|
| `--digests` | | Show digests |
|
|
|
|
|
| `--filter, -f` | | Filter output based on conditions provided |
|
|
|
|
|
| `--format` | | Pretty-print images using a Go template |
|
|
|
|
|
| `--no-trunc` | | Don’t truncate output |
|
|
|
|
|
| `--quiet, -q` | | Only show numeric IDs |
|
2022-03-19 14:19:55 +01:00
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
### Remove one or more containers
|
|
|
|
|
|
2023-01-15 18:17:59 +01:00
|
|
|
|
```Shell
|
2022-03-19 14:19:55 +01:00
|
|
|
|
docker rm [OPTIONS] CONTAINER [CONTAINER...]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Options
|
|
|
|
|
|
|
|
|
|
| Name, shorthand | Default | Description |
|
2023-01-15 18:19:48 +01:00
|
|
|
|
|:----------------|:-------:| ------------------------------------------------------- |
|
|
|
|
|
|`--force, -f` | | Force the removal of a running container (uses SIGKILL) |
|
|
|
|
|
|`--link, -l` | | Remove the specified link |
|
|
|
|
|
|`--volumes, -v` | | Remove anonymous volumes associated with the container |
|
2022-03-19 14:19:55 +01:00
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
### Stop one or more running containers
|
|
|
|
|
|
2023-01-15 18:17:59 +01:00
|
|
|
|
```Shell
|
2022-03-19 14:19:55 +01:00
|
|
|
|
docker stop [OPTIONS] CONTAINER [CONTAINER...]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Options
|
|
|
|
|
|
|
|
|
|
| Name, shorthand | Default | Description |
|
2023-01-15 18:21:04 +01:00
|
|
|
|
|:----------------|:-------:| ------------------------------------------- |
|
|
|
|
|
|`--time, -t` | 10 | Seconds to wait for stop before killing it. |
|
|
|
|
|
|
|
|
|
|
## How to cleanup (unused) resources
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...
|
|
|
|
|
|
|
|
|
|
If you use a Docker version newer than > 1.13 you can use Dockers builtin cleanup tool `purge`.
|
|
|
|
|
|
|
|
|
|
### The new way (Docker > 1.13)
|
|
|
|
|
|
|
|
|
|
#### Network
|
|
|
|
|
|
|
|
|
|
To purge the networks ([Docker Docs](https://docs.docker.com/engine/reference/commandline/network_prune))
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker network prune
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Containers, Volumes, Images
|
|
|
|
|
|
|
|
|
|
And to purge the docker system ([Docker Docs](https://docs.docker.com/engine/reference/commandline/system_prune))
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker system prune
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### The old way (Docker < 1.13)
|
|
|
|
|
|
|
|
|
|
#### Delete Volumes
|
|
|
|
|
|
|
|
|
|
{{< alert theme="info" >}} // see: https://github.com/chadoe/docker-cleanup-volumes {{< /alert >}}
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker volume rm $(docker volume ls -qf dangling=true)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker volume ls -qf dangling=true | xargs -r docker volume rm
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Delete Networks
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker network ls
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker network ls | grep "bridge"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
```Shell
|
|
|
|
|
docker network ls | awk '$3 == "bridge" && $2 != "bridge" { print $1 }'
|
2024-02-13 22:37:17 +01:00
|
|
|
|
```
|