This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| docker [2021/08/28 01:19] – 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 |
| - | | + | <code bash> |
| + | docker logs -f container_name | ||
| + | </ | ||
| ==== Information on a container ==== | ==== 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 ==== | ==== 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. | ||
| ---- | ---- | ||
| Line 76: | Line 106: | ||
| } | } | ||
| - | Then restart Docker and you’ll be good to go. | ||
| - | ---- | + | This will keep 10Gb of log files, so adjust accordingly |
| - | ==== Use the first 4 letters | + | |
| - | | + | Then restart Docker with '' |
| - | You only need to reference the first 4 characters of the ID for it to work. | + | ---- |
| - | ---- | ||
| ==== Great site with tips, where some of the above ones are coming from ==== | ==== Great site with tips, where some of the above ones are coming from ==== | ||
| https:// | https:// | ||