Homelab Troubleshooting

Tips on running a Linux server and docker.

User Tools

Site Tools


docker

Docker Hints and Tips

Docker needs daily or at least weekly maintenance with the help of the following command:

docker system prune -f

You should probably put that one on a systemd timer just in case.

General maintenance

Prune Unused Images

docker image prune -a

Information gathering

Check docker Disk Usage

docker system df

List all containers, running or stopped

docker ps -a

Pretty print the container info

docker ps --format "table {{.Names}}\t{{.Status}}\t \
  {{.Networks}}\t{{.Ports}}\t{{.Size}}"

Follow the log of your app

docker logs -f container_name

Information on a container

docker container inspect container_name

Networking

Check all Networks

docker network ls

Prune Unused Networks

docker network prune

Get network information

docker network inspect network_name  

Container handling

Enter a container

docker attach mybb_mybb_1 

Show container history

docker history mybb/mybb:latest 

Get container interactive shell

docker exec -it mybb_mybb_1 /bin/sh

Stopping containers with specific name

docker container stop $(docker container ls -q --filter name=myapp*)

Bash function / alias to get a list of Docker image tags:

dtags () {
    local image="${1}"
 
    wget -q https://registry.hub.docker.com/v1/repositories/"${image}"/tags -O - \
        | tr -d '[]" ' | tr '}' '\n' | awk -F: '{print $3}'
}

Find containers from the command line

docker search ruby --filter="is-official=true"

Use the first 4 letters of a container hash to reference it

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):

"log-driver": "json-file",
"log-opts": {
  "max-size": "10m",
  "max-file": "1000"
}

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

docker.txt · Last modified: 2022/05/28 18:32 by alexk7110