Inspect Docker Image with dive

Install dive
brew install dive

Now we can run dive against any Docker image we wish to inspect…​

Run dive
dive confluentinc/cp-kafka:5.4.3
dive console
Figure 1. Screenshot of dive analyzing the Kafka Docker image

Resources:

Introspect Private Docker Registry

List images:

curl -s https://the-registry-url/v2/_catalog

Get tags for an image

curl -s https://the-registry-url/v2/the-image-name/tags/list

An example:

curl -s https://registry.local/v2/alpine/rabbitmq/tags/list
{"name":"alpine/rabbitmq","tags":["3.9.17"]}

Run Trivy Scan for Docker Image

docker run aquasec/trivy image IMAGE:TAG

Search for image

docker search mysql

Run local MySQL Database

docker run --name local-mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:5.7

Run bash in container

docker exec -it NAME /bin/bash

Run local Postgres Database

docker run --name some-pg-db -p5432:5432 -e POSTGRES_PASSWORD=fancypassword -e POSTGRES_USER=theuser postgres:latest

Run Postgres Client from Docker Image

docker run --rm -it postgres:14.0 psql -h <host> -U <username> -d <database>

or connect to running postgres instance:

docker exec -it my-postgres psql -U postgres

Generate OpenAPI Documentation in AsciiDoc

Pull Docker Image

docker pull openapitools/openapi-generator-cli

Generate AsciiDoc

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/fahrwege-api.yml -g asciidoc -o /local/adoc-fw

Find dangling / untagged images

docker images -f "dangling=true" -q

Resources:

Convert Word to AsciiDoc with Pandoc

docker run --rm --volume "`pwd`:/data" --user `id -u`:`id -g` pandoc/core my-in-file.docx -f docx -t asciidoc --wrap=none --markdown-headings=atx --extract-media=extracted-media  -o my-out-file.adoc

Change Auto-Restart Policy

e.g. disable auto-restart for container

docker update --restart no <IMAGE_NAME>

Output Images as CSV List

Used in GitLab builds for Trivy ..

docker image ls --format="{{.Repository}}:{{.Tag}}" | grep -v '<none>' | tr '\n' ','

Package OpenSSL as Docker Image

Dockerfile
FROM alpine:3.18
RUN apk add --no-cache openssl
ENTRYPOINT ["openssl"]
Building the image
docker build . -t openssltool
Running openssl
docker run openssltool

Prune Volumes

Helps with errors like initdb: error: could not create directory "/var/lib/postgresql/data/pg_wal": No space left on device

docker volume prune

or prune even more

docker system prune --volumes