Skip to content

Docker & Podman: Build, deploy & roll back

Docker & Podman commands for build, deploy & roll back (tags: #deploy #build #rollback #release #compose).

Index
8 items

Docker6

Docker: Follow logs of all compose services

Safe

Interleaved logs from every service in the compose project. Add a service name to narrow it.

docker compose logs -f --tail 100
What each part does
  1. docker compose logslogs of every service in the compose project, prefixed by service name
  2. -ffollow new lines
  3. --tail 100last 100 lines per service to start with

Also known as: docker-compose logs · compose logs

Docker: Build and tag an image

Safe

Build from the Dockerfile in the current directory and tag for a registry.

docker build -t <registry>/<image>:<tag> .
What each part does
  1. docker buildbuild an image from a Dockerfile
  2. -t <registry>/<image>:<tag>name and tag the result, ready to docker push
  3. .build context: the current directory (sent to the daemon; .dockerignore applies)

Also known as: docker build

Docker: Redeploy a compose service with a new image

Safe

Pull the latest tag and recreate only that service.

docker compose pull <service> && docker compose up -d <service>
What each part does
  1. docker compose pull <service>download the newest image for the service's tag
  2. &&only continue if the pull worked
  3. docker compose up -d <service>recreate the service if its image or config changed, detached

Also known as: compose update · restart service

Docker: Patch OS packages in a Debian or Ubuntu Dockerfile

Safe

Dockerfile line: pulls in all security fixes for the base image at build time. Put it right after FROM.

RUN apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/*
What each part does
  1. apt-get updaterefresh package lists
  2. apt-get upgrade -yupgrade every installed package
  3. rm -rf /var/lib/apt/lists/*keep the image small

My note Only build fixes when the build is not cached: docker build --pull --no-cache

  • #docker
  • #patching
  • #build
  • #vulnerabilities

Also known as: dockerfile apt upgrade · patch container image · fix image cve

Docker: Patch OS packages in an Alpine Dockerfile

Safe

Dockerfile line: upgrade every Alpine package to the latest fixed version at build time.

RUN apk upgrade --no-cache
What each part does
  1. apk upgradeupgrade all installed packages
  2. --no-cachedo not keep the package index in the image
  • #docker
  • #patching
  • #build
  • #vulnerabilities

Also known as: dockerfile apk upgrade · alpine cve · patch alpine image

Docker: Rebuild an image with the latest base image

Safe

Most image CVEs are fixed by rebuilding: a fresh base image plus re-run package installs.

docker build --pull --no-cache -t <image>:<tag> .
What each part does
  1. --pullalways download the newest version of the FROM image
  2. --no-cachere-run every step so apt/apk get today's fixes
  3. -t <image>:<tag>name the result

My note Scan before pushing: trivy image --severity HIGH,CRITICAL --ignore-unfixed <image>:<tag>

  • #docker
  • #patching
  • #build
  • #vulnerabilities

Also known as: rebuild image · refresh base image · fix image vulnerabilities

Podman2

Podman: Create a pod with a published port

Safe

A pod shares one network namespace between containers, like a Kubernetes pod. Add containers with --pod <pod>.

podman pod create --name <pod> -p <host-port>:<container-port>
What each part does
  1. podman pod createcreate a pod: containers in it share network and localhost
  2. --name <pod>the pod's name
  3. -p <host-port>:<container-port>publish a port; must be set on the pod, not on its containers

Also known as: podman pod

Podman: Generate a systemd unit for a container

Safe

Writes container-<name>.service so systemd can manage the container.

podman generate systemd --new --files --name <container>
What each part does
  1. podman generate systemdwrite a systemd unit for a container (newer Podman prefers Quadlet files)
  2. --newthe unit creates a fresh container on start and removes it on stop
  3. --fileswrite .service files to the current directory instead of stdout
  4. --name <container>use the container name (not ID) in the unit

My note Deprecated in favour of Quadlet (.container files in ~/.config/containers/systemd/) on Podman 4.4+.

Also known as: podman systemd · quadlet

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…