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: !reset and !override remove or replace values in a Compose override file

Docker
~/tips/tip-docker-compose-reset-override-tags

ports: !reset []

Drop a published port or replace a whole list from an override file.

An override file normally adds to lists. So if the base file publishes 8080:80, an override can add more ports but has no plain way to take that one away. The YAML tags !reset and !override fix that.

!reset clears an attribute back to its default. !override replaces it completely, skipping the normal merge rules.

# compose.override.yaml: no published ports on this machine
services:
  web:
    ports: !reset []
# compose.prod.yaml: only this port, nothing from the base file
services:
  web:
    ports: !override
      - "127.0.0.1:9090:80"

Without the tag, the production file would leave you with both 8080:80 and the new port, because ports are merged by appending. I’d guess that is the most common reason a port stays open after someone thought they had removed it.

You can also reset a single environment variable with FOO: !reset null. The value you write after !reset is ignored, so [] or null is only there to keep the YAML readable.

These tags are Compose specific. Other YAML tools that read the same file may choke on them or drop them, so check with docker compose config rather than a generic linter.

Further reading: Compose file reference: merge

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