Open DanielBaulig opened 5 months ago
My guess is that depends_on containers still expose their service ports
indeed. "one-off" container started by run
command doesn't get ports exposed by default, as the run
command is designed to run maintenance scripts and not main service. But dependencies run as services, so get ports exposed.
I guess your issue here is that you want to run with a dedicated test
project name, so the conflict with the running services already using ports. Why do you override project name? You should just run your test container and rely on existing services.
It might be useful to call out this behavior explicitly in the documentation. I read the run
and --service-ports
documentation multiple times and it wasn't clear to me that this is expected behavior.
I need to run the tests in a separate instance of the services for state reasons. I want to have close control over the state of the application and service and not pollute / interfere with the state of my development environment. For example I want to cover the case of spinning up / updating the service containers in production. If I was running the tests against an already active instance of the application I would not get that.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Description
I am using
docker compose --profile=tests --project=tests run
to run isolated tests in my development environment. The documentation of docker compose run states that no service ports will get published to the host unless --service-ports=true is specified.However, my tests www container seems to fail to start for failing to bind ports if I have my development container running at the same time. Note that the container being run is not the www container, but the tests container, which however depends_on the www container, My guess is that depends_on containers still expose their service ports even when no --service-ports=true is specified.
Output of
docker comose --verbose run
belowIf this is intended behavior, then the documentation for docker compose run should be explicit about it. Nothing currently makes it clear that this is how it's expected to work.
Steps To Reproduce
Container A that depends_on container B. Container B has published ports in the compose.yml. When container A is started with
docker compose run
, container B will get started as a dependency, too, but will have it's ports published, even though no--service-ports
was provided.Compose Version
Docker Environment
Anything else?
No response