brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker image inspect shows ports, user and variables before you run an image

Docker
~/tips/tip-docker-image-inspect-config

docker image inspect --format '{{json .Config.ExposedPorts}}' nginx:alpine

Read an image's default ports, user, environment and stop signal without starting it.

Before I write a Compose entry for an unfamiliar image, I want to know which port it listens on, which user it runs as and which variables it already sets. All of that is in the image config.

docker image inspect --format '{{json .Config.ExposedPorts}}' nginx:alpine
docker image inspect --format '{{.Config.User}}' nginx:alpine
docker image inspect --format '{{json .Config.Env}}' nginx:alpine

For nginx:alpine that shows port 80/tcp, an empty user (so root), and variables like NGINX_VERSION. Other useful fields are .Config.Entrypoint, .Config.Cmd, .Config.WorkingDir, .Config.Volumes and .Config.StopSignal, which for nginx is SIGQUIT.

To see everything at once, pipe it through jq:

docker image inspect nginx:alpine | jq '.[0].Config'

The Volumes list is worth a look: each path there gets an anonymous volume when you run the image without mounting something on it.

ExposedPorts is documentation written by the image author, not a promise. An app can listen on a different port than it exposes, or on several. If a port does not answer, check inside the container what really listens. The image has to be pulled first; for a remote image, docker buildx imagetools inspect shows the manifest without downloading it.

Further reading: docker image inspect

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link