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/28 01:16] 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> 
 +docker logs -f container_name 
 +</code> 
 ==== Information on a container ==== ==== Information on a container ====
-  docker container inspect container_name   +<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 ==== ==== Find containers from the command line ====
-  docker search ruby --filter="is-official=true" +<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.
  
 ---- ----
Line 76: Line 106:
   }   }
  
-Then restart Docker and you’ll be good to go.+ 
 +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.
  
 ---- ----
-==== Use the first 4 letters of a container hash to reference it ==== 
  
-  docker image inspect f4f4 +==== Great site with tips, where some of the above ones are coming from ==== 
- +https://nickjanetakis.com/blog/tag/docker-tips-tricks-and-tutorials
-You only need to reference the first 4 characters of the ID for it to work.+
docker.1630102560.txt.gz · Last modified: 2021/08/28 01:16 by alexk7110