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 compose run --service-ports publishes the ports for a one-off run

Docker
~/tips/tip-compose-run-service-ports

docker compose run --rm --service-ports web

Starts a one-off compose container with its published ports mapped to the host.

It is easy to assume docker compose run behaves like up for a single service. It does not publish the ports from your compose file, so a web app can look dead when it is only closed.

The docs say it plainly: run skips the service’s configured ports so they do not collide with ports already open. To get them back, add --service-ports (short form -P):

docker compose run --rm --service-ports web

That starts one container of web with every port from its ports: list mapped to the host. It works well for running a web service in the foreground and watching its output while you test a setting. To publish just one port, use -p 8081:80 and keep the rest closed. You can also replace the command and keep the ports, for example docker compose run --rm --service-ports web sh for a shell in a container the host can reach.

Caveat: if the normal stack is already running and holds the same host port, the one-off container cannot bind it and fails to start. Stop that service first, or pick another host port with -p. Linked services that are not running get started for you unless you add --no-deps.

Further reading: docker compose run

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