System Management
Autostart Docker Compose in Ubuntu
- Assuming Ubuntu Server LTS 24.04 is used
- Assuming Docker got installed via Snap!
# Host configuration files in your home directory (snap has only limited access)
mkdir /home/user/docker/mssql
# Create your config
vim /home/user/docker/mssql/compose.yaml
# Test if it works
docker compose -f /home/user/docker/mssql.compose.yaml
# Create service file
sudo vim /etc/systemd/system/mssql.service
[Unit]
Description=MSSQL Docker Compose Service
Requires=snap.docker.dockerd.service
After=snap.docker.dockerd.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/home/user/docker/mssql
ExecStart=/snap/bin/docker compose up -d
ExecStop=/snap/bin/docker compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
# Start and test
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable mssql.service
sudo systemctl start mssql.service
sudo systemctl status mssql.service
Image Management
List local images
docker image ls
Build an image
docker build . -t image:tag
Build images locally using unique tagging
# Leveraging PowerShell
docker build . -t image:$(get-date -Format "yyyyMMddHHmmss")
Remove images
# Option 1
docker image rm image:tag
# Option 2
docker rmi image:tag
# Option 3
docker rmi <imageid>
# Option 4
docker rmi <only-first-characters-of-image-id>
Inspect image content
# Option 1
docker run -it image:tag sh
# Option 2
docker run -it --entrypoint sh image:tag
# Option 3
docker image history --no-trunc image:tag > image_history
Container Management
List running containers
docker container ls
Run interactively and remove afterward
docker run -it --rm image:tag sh
docker run --interactive --tty --rm image:tag sh
Exposing ports
docker run -it -p <localPort>:<containerPort> image:tag
Stop and remove a running container
# Instead of
docker container stop foobar
docker container rm foobar
# Use ...
docker rm foobar --force
# Or
docker rmi -f foobar
Volumes
Bind mount a single file into a container
podman run --rm -ti -v c:\\temp\\fluent-bit.conf:/etc/fluent-bit.conf cr.fluentbit.io/fluent/fluent-bit:2.2.0 -c /etc/fluent-bit.conf
Misc
Difference between Image ID and digest
- The digest is a hash of the manifest, introduced in Docker registry v2
- The image ID is a hash of the local image JSON configuration
Run Postgres locally
docker run -p 5432:5432 -v postgres-11-volume:/var/lib/postgresql/data --env POSTGRES_PASSWORD=postgres --name postgres-11 postgres:11 --restart=always