Homelab Troubleshooting

Tips on running a Linux server and docker.

User Tools

Site Tools


docker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
docker [2021/08/27 23:31] alexk7110docker [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:
-  docker system prune -f +<code bash> 
- You should probably put that one on a systemd timer just in case.+docker system prune -f 
 +</code> 
 +You should probably put that one on a systemd timer just in case.
  
 ===== General maintenance ===== ===== General maintenance =====
 ==== Prune Unused Images ==== ==== Prune Unused Images ====
-  docker image prune -a +<code bash> 
 +docker image prune -a 
 +</code>
 ===== Information gathering ===== ===== Information gathering =====
 ==== Check docker Disk Usage ==== ==== Check docker Disk Usage ====
-  docker system df +<code bash> 
-==== List all containers ==== +docker system df 
-  docker ps -a+</code> 
 +==== List all containers, running or stopped ==== 
 +<code bash> 
 +docker ps -a 
 +</code>
 ==== Pretty print the container info ====   ==== Pretty print the container info ====  
-  docker ps --format "table {{.Names}}\t{{.Status}}\t \ +<code bash> 
-    {{.Networks}}\t{{.Ports}}\t{{.Size}}" +docker ps --format "table {{.Names}}\t{{.Status}}\t \ 
-==== Follow a container'log ==== +  {{.Networks}}\t{{.Ports}}\t{{.Size}}" 
-  docker logs -f container_name +</code> 
-==== Information on a network ==== +==== Follow the log of your app ==== 
-  docker network inspect network_name   +<code bash> 
-==== Information on a container ==== +docker logs -f container_name 
-  docker container inspect container_name  +</code>
  
 +==== Information on a container ====
 +<code bash>
 +docker container inspect container_name
 +</code>
 ---- ----
 ===== Networking ===== ===== Networking =====
 ==== Check all Networks ==== ==== Check all Networks ====
-  docker network ls+<code bash> 
 +docker network ls 
 +</code>
 ==== Prune Unused Networks ==== ==== Prune Unused Networks ====
-  docker network prune +<code bash> 
 +docker network prune 
 +</code> 
 +==== Get network information ==== 
 +<code bash> 
 +docker network inspect network_name   
 +</code>
 ---- ----
 ===== Container handling ===== ===== Container handling =====
 ==== Enter a container ==== ==== Enter a container ====
-  docker attach mybb_mybb_1 +<code bash> 
 +docker attach mybb_mybb_1  
 +</code>
 ==== Show container history ==== ==== Show container history ====
-  docker history mybb/mybb:latest +<code bash> 
 +docker history mybb/mybb:latest  
 +</code>
 ==== Get container interactive shell ==== ==== Get container interactive shell ====
-  docker exec -it mybb_mybb_1 /bin/sh +<code bash> 
- +docker exec -it mybb_mybb_1 /bin/sh 
-Stopping containers with specific name +</code> 
-  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*) 
 +</code>  
 ==== 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="${1}"
  
-  dtags () { +    wget -q https://registry.hub.docker.com/v1/repositories/"${image}"/tags -O - \ 
-      local image="${1}" +        | tr -d '[]" ' | tr '}' '\n' | awk -F: '{print $3}' 
-   +
-      wget -q https://registry.hub.docker.com/v1/repositories/"${image}"/tags -O - \ +</code> 
-          | tr -d '[]" ' | tr '}' '\n' | awk -F: '{print $3}'+==== Find containers from the command line ==== 
 +<code bash> 
 +docker search ruby --filter="is-official=true" 
 +</code> 
 +==== Use the first 4 letters of a container hash to reference it ==== 
 +<code bash> 
 +docker image inspect f4f4 
 +</code> 
 +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): 
 + 
 +  "log-driver": "json-file", 
 +  "log-opts":
 +    "max-size": "10m", 
 +    "max-file": "1000"
   }   }
  
-==== Find containers from the command line ==== + 
-  docker search ruby --filter="is-official=true"+This will keep 10Gb of log files, so adjust accordingly 
 + 
 +Then restart Docker with ''sudo systemctl restart docker.service'' and you’ll be good to go. 
 + 
 +---- 
 + 
 +==== Great site with tips, where some of the above ones are coming from ==== 
 +https://nickjanetakis.com/blog/tag/docker-tips-tricks-and-tutorials
docker.1630096310.txt.gz · Last modified: 2021/08/27 23:31 by alexk7110