Docker Installation
Links
Related
Cleanup cronjob
0 4 * * * /usr/bin/docker container prune -f && /usr/bin/docker image prune -f
Install from distro APT
apt install -y gnupg2 pass apparmor-utils docker.io docker-compose docker-compose-plugin
Docker stop all
docker stop $(docker ps -a -q)
or
docker ps -q | % { docker stop $_ }
Search trough logs
docker logs --since "$(date -d 'today 13:30' +'%Y-%m-%dT%H:%M:%S')" --until "$(date -d 'today 13:40' +'%Y-%m-%dT%H:%M:%S')" prodapp
Manually cleanup old logs
As root, not with sudo!
truncate -s 0 /var/lib/docker/containers/**/*-json.log
Install from Docker APT
sudo apt-get update && sudo apt-get install ca-certificates curl && sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Remove all containers from a host
docker rm -f $(docker ps -qa)
Remove all volumes from a host
docker volume rm $(docker volume ls -q)
Login with PAT
Create a new Personal Access Token here.
export PAT=.....
echo $PAT | docker login ghcr.io --username doesnt@matter.com --password-stdin
echo $PAT | docker login registry.gitlab.com -u aiketestuser1 --password-stdin
or
echo "ghp_REPLACE_ME" | docker login ghcr.io --username doesnt@matter.com --password-stdin
Filter docker ps columns
Link: docker docs
docker ps -a --format="table {{.Names}}\t{{.Ports}}\t{{.CreatedAt}}\t{{.Status}}\t{{.Mounts}}"
Run sleep in a container that won’t start
docker run --rm --entrypoint sh ubuntu:latest -c "sleep infinity"
Log rotation
In /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
}
}
or use Logrotate!
/var/lib/docker/containers/*/*.log {
rotate 7
daily
compress
missingok
delaycompress
copytruncate
}
Show log file sizes
sudo find /var/lib/docker/containers/ -name *-json.log -exec ls -lh {} \;
Check log rotation status for container
docker inspect -f '' your_container
Truncate logfile manually
If you don’t want to recreate the container.
truncate -s 0 /var/lib/docker/containers/<container-id>/<container-id>-json.log
Docker prune
docker image prune -af --filter "until=24h"