Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code, you can significantly reduce the delay between writing code and running it in production.

ToolDescription
LazydockerThe lazier way to manage everything docker
DiveA tool for exploring each layer in a docker image
HadolintDockerfile linter, validate inline bash, written in Haskell
Depend on Docker {DoD}Open-source project that helps you containerize your software
GrypeA vulnerability scanner for container images and filesystems
TrivyFind vulnerabilities, misconfigurations, secrets
CtopTop-like interface for container metrics
EdgesharkDiscover and capture container network
SkopeoWork with remote images registries
DockercContainer image to single executable compiler
Deploy multiple dockers with Docker Compose

Articles/Talks

Installation

get.docker

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Configuration

# modify for builtkit
vim /etc/docker/daemon.json
 
{
	# activate buildkit by default
	"features": {"buildkit": true},
    "bip": "10.0.20.10/16",
    "dns": ["172.18.18.101", "172.18.18.102"] ,
    "dns-search": ["nameserver.com"] ,
    "live-restore": true,
    "log-opts": {"max-size": "25m", "max-file": "4"},
    "insecure-registries" : ["registry.es:5000"] ,
    "registry-mirrors": ["https://registry.es:5000"],
    # subnet
    "default-address-pools":
      [
         {"base":"10.1.0.0/16","size":24}
      ]
}
# for docker-compose add
export COMPOSE_DOCKER_CLI_BUILD=1
# Show docker configuration for Registries
cat $HOME/.docker/config.json
# SYSTEMD
sudo systemctl daemon-reload
sudo systemctl restart docker
# display docker enviroments variables
sudo systemctl show docker --property Environment

Configure variables for proxy in docker daemon

Debug

The output you are showing is from buildkit, which is a replacement for the classic build engine that docker ships with. You can adjust output from this with the --progress option:

  --progress string         Set type of progress output (auto, plain, tty). Use plain to show container output
                            (default "auto")

Adding --progress=plain will show the output of the run commands that were not loaded from the cache. This can also be done by setting the BUILDKIT_PROGRESS variable:

export BUILDKIT_PROGRESS=plain

MacOS

  • Configuration for docker-compose caveats and add it as plugin and colima for VM.
{
        "cliPluginsExtraDirs": [
            "/opt/homebrew/lib/docker/cli-plugins"
        ],
        "auths": {},
        "credsStore": "osxkeychain",
        "currentContext": "colima"
}
# ssh to VM
colima ssh

Commands

Run

docker run -it --entrypoint /bin/bash image:latest

Run Ubuntu

docker run -it --rm ubuntu
apt update && apt install -y curl python3 python3-pip python3-venv

Run IT-tools

docker run -d --name it-tools --restart unless-stopped -p 8080:80 corentinth/it-tools:latest

Networking

# Attach a running container to a network
docker network connect [network] [container]

Logging

docker logs ID_CONTAINER -f

Inspect

# show IP Docker
docker inspect -f '{{.NetworkSettings.IPAddress}}' ID or Name
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ID or Name
# list all containers belonging to a network by name
docker inspect -f '{{range $key, $value := .NetworkSettings.Networks}}{{$key}} {{end}}' ID or Name
#show volumes
docker inspect -f '{{json .Mounts}}' ID | jq .

System

# Show information about space used for Docker
docker system df

Stats

docker stats

Security

### SBOM generation (CycloneDX format)
RUN --mount=type=cache,target=/root/.cache/pip \
    python -m pip install cyclonedx-bom \
 && cyclonedx-py -o /install/sbom.json

Registry

"insecure-registries" : ["registry.es:5000"]
  • Create registry
docker run -d -p 5000:5000 --name registry registry:2
docker image tag ubuntu localhost:5000/myfirstimage
docker push localhost:5000/myfirstimage
  • Push image to Docker Registry
docker login -u <user> -p <pass> https://url
docker tag image:latest url/image:latest
docker push url/image:latest

Operations

Stop all containers

docker stop $(docker ps -q)

Show process machine

docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged ubuntu top
 
docker exec -it CONTAINER_ID bash top

Show volume information

docker run -it --rm -v /path/on/host:/vol busybox ls -l /vol

Move volume information to other volume

docker volume create --name newvolume && docker run --rm -it -v oldvolume:/from -v newvolume:/to alpine ash -c 'cd /from ; cp -av . /to' && docker volume rm oldvolume

Docker delete

Delete all

docker system prune -a

Delete unused or dangling

Images, Containers, Volumes, and Networks

docker system prune
docker volume prune

Delete unused containers

docker rm $(docker ps -aq)

Delete build cache

docker builder prune

Delete images dangling

docker rmi $(docker images -qf "dangling=true")
docker rmi $(docker images | grep "<none>" | awk '{print $3}')
 
# remove last 5 images
docker rm $(docker images -q | tail -n 5)

Virtual machines

MCP

 docker mcp secret set POSTGRES_PASSWORD=my-secret-password