This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
docker [2021/08/27 23:30] – alexk7110 | docker [2022/05/28 18:32] (current) – alexk7110 | ||
---|---|---|---|
Line 2: | Line 2: | ||
**Docker needs daily or at least weekly** maintenance with the help of the following command: | **Docker needs daily or at least weekly** maintenance with the help of the following command: | ||
- | | + | <code bash> |
- | You should probably put that one on a systemd timer just in case. | + | docker system prune -f |
+ | </ | ||
+ | You should probably put that one on a systemd timer just in case. | ||
===== General maintenance ===== | ===== General maintenance ===== | ||
==== Prune Unused Images ==== | ==== Prune Unused Images ==== | ||
- | | + | <code bash> |
+ | docker image prune -a | ||
+ | </ | ||
===== Information gathering ===== | ===== Information gathering ===== | ||
==== Check docker Disk Usage ==== | ==== Check docker Disk Usage ==== | ||
- | | + | <code bash> |
- | ==== List all containers ==== | + | docker system df |
- | docker ps -a | + | </ |
+ | ==== List all containers, running or stopped | ||
+ | <code bash> | ||
+ | docker ps -a | ||
+ | </ | ||
==== Pretty print the container info ==== | ==== Pretty print the container info ==== | ||
- | | + | <code bash> |
- | {{.Networks}}\t{{.Ports}}\t{{.Size}}" | + | docker ps --format "table {{.Names}}\t{{.Status}}\t \ |
- | ==== Follow | + | {{.Networks}}\t{{.Ports}}\t{{.Size}}" |
- | docker logs -f container_name | + | </ |
- | ==== Information on a network ==== | + | ==== Follow |
- | docker network inspect network_name | + | <code bash> |
- | ==== Information on a container ==== | + | docker logs -f container_name |
- | docker container inspect container_name | + | </ |
+ | ==== Information on a container ==== | ||
+ | <code bash> | ||
+ | docker container inspect container_name | ||
+ | </ | ||
---- | ---- | ||
===== Networking ===== | ===== Networking ===== | ||
==== Check all Networks ==== | ==== Check all Networks ==== | ||
- | | + | <code bash> |
+ | docker network ls | ||
+ | </ | ||
==== Prune Unused Networks ==== | ==== Prune Unused Networks ==== | ||
- | | + | <code bash> |
+ | docker network prune | ||
+ | </ | ||
+ | ==== Get network information ==== | ||
+ | <code bash> | ||
+ | docker network inspect network_name | ||
+ | </ | ||
---- | ---- | ||
===== Container handling ===== | ===== Container handling ===== | ||
==== Enter a container ==== | ==== Enter a container ==== | ||
- | | + | <code bash> |
+ | docker attach mybb_mybb_1 | ||
+ | </ | ||
==== Show container history ==== | ==== Show container history ==== | ||
- | | + | <code bash> |
+ | docker history mybb/ | ||
+ | </ | ||
==== Get container interactive shell ==== | ==== Get container interactive shell ==== | ||
- | | + | <code bash> |
- | + | docker exec -it mybb_mybb_1 /bin/sh | |
- | Stopping containers with specific name | + | </ |
- | docker container stop $(docker container ls -q --filter name=myapp*) | + | ==== Stopping containers with specific name ==== |
- | | + | <code bash> |
+ | docker container stop $(docker container ls -q --filter name=myapp*) | ||
+ | </ | ||
==== Bash function / alias to get a list of Docker image tags: ==== | ==== Bash function / alias to get a list of Docker image tags: ==== | ||
+ | <code bash> | ||
+ | dtags () { | ||
+ | local image=" | ||
- | dtags () { | + | |
- | local image=" | + | | tr -d ' |
- | + | } | |
- | | + | </ |
- | | tr -d ' | + | ==== Find containers from the command line ==== |
+ | <code bash> | ||
+ | docker search ruby --filter=" | ||
+ | </ | ||
+ | ==== Use the first 4 letters of a container hash to reference it ==== | ||
+ | <code bash> | ||
+ | docker image inspect f4f4 | ||
+ | </ | ||
+ | You only need to reference the first 4 characters of the ID for it to work. | ||
+ | |||
+ | ---- | ||
+ | ==== Change the default log policy ==== | ||
+ | By default, Docker captures the standard output (and standard error) of all your containers, and writes them in files using the JSON format. | ||
+ | |||
+ | So right away we know that Docker is managing its own log files for containers. | ||
+ | |||
+ | If we look further down in the docs we can see that the max-size option defaults to -1 which means the log’s file size will grow to unlimited size. There’s also the max-file option which defaults to keeping around 1 log file. | ||
+ | |||
+ | |||
+ | We can change this by editing the daemon.json file which is located in /etc/docker on Linux. On Docker for Windows / Mac you can open up your settings and then goto the “Daemon” tab and flip on the “Advanced” settings. | ||
+ | |||
+ | |||
+ | Add this into your daemon.json to cap your container logs to 10gb (1,000x 10mb files): | ||
+ | |||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
} | } | ||
+ | |||
+ | This will keep 10Gb of log files, so adjust accordingly | ||
+ | |||
+ | Then restart Docker with '' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Great site with tips, where some of the above ones are coming from ==== | ||
+ | https:// |