"docker compose run" should warn when "ports" configuration is available but "--service-ports" is not supplied
Description
When you have a docker-compose.yml that contains ports entries, for example:
---
services:
web:
image: crccheck/hello-world
ports:
- 8000:8000then this works as expected with "compose up":
# docker compose up web
Attaching to web-1
web-1 | httpd startedI can then reach the service from the host, and also from another system.
When doing "run", things seems similarly OK:
# docker compose run web
Container tmp-web-run-25ac0b9f7167 Creating
Container tmp-web-run-25ac0b9f7167 Created
httpd startedBut now I cannot reach the container, not from the host, not from another system.
Turns out that I should have RTFM, because in there it says:
If you do want the service’s ports to be created and mapped to the host, specify the
--service-ports
This came unexpected and cost me a few hours. I think it would be a Good Idea™ to have docker compose run print something like this:
WARNING the compose file contains explicit
portsstatements, but those won't be effective unless you supply the--service-portsargument
Such a message would prevent other people from getting stuck, while being harmless and not affect any functionality.
Source: docker/compose