Is there a reason to use run
to start up a docker-compose.yml
file or should you just use up
?
I understand that run
can start up a specific container, but I am referring to the case where you use it without specifying a container so that it starts up all of your yml containers.
I'd like to point out that if you're using Python with the pdb debugger:
It will not drop to the shell if you execute your script using:
However if you use run, it will drop down to the debugger as expected:
As mentioned in
docker-compose run
:So unless you have those specific needs (overriding a command or running only one container on different ports),
docker-compose up
(even for one container) is enough.Simply because
docker-compose run
is made to run one-off commands for your services.That means that, if you already did a
docker-compose up
, all your containers are already running on their specified ports fromdocker-compose.yml
.Doing a
docker-compose run
at this stage (to execute a one-off command), if it was respecting the same port, would fail immediately. Hence the default non-creation of those ports.Another use case (in Compose environment variables reference):