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: set both image: and build: in Compose to give your build a proper name

Docker
~/tips/tip-docker-compose-image-and-build

build: .

Tag the image Compose builds so you can push, reuse or roll it back.

With only build: ., Compose names the image after the project and service, something like myproject-app. Add an image: line next to it and that becomes the tag of the result.

services:
  app:
    build: .
    image: registry.example.com/app:1.4.0
docker compose build app
docker compose push app

Now the build produces registry.example.com/app:1.4.0, and docker compose push knows where to send it. On another machine the same file can pull that tag instead of building, as long as the image exists in the registry.

I like this for small self-built tools. Bumping the version in the image: line means the old build stays on disk under its own tag, so going back is a matter of changing the line again.

Compose decides whether to build or pull based on pull_policy. By default it pulls when the image is missing and builds only when the pull fails, which can quietly start an old image from the registry instead of your local changes. During development, run docker compose up -d --build to be sure the image is rebuilt, or set pull_policy: build on that service.

Further reading: Compose Build Specification

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