I have read https://docs.docker.com/compose/reference/run/, and I found that I can run a single service like web
service here:
docker-compose run web
Can I run in a single line two or more services like this?
docker-compose run web, backup
It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.
The docker-compose. yml file allows you to configure and document all your application's service dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).
So there is no conflict if multiple containers are using the same port ( :80 in this case). You can access one container from another using its container-name or service-name or ip-address, whereas ip-address is not a good idea because this might change every time you (re)start the container.
Currently docker-compose run
does not allow specifying multiple services, and there aren't any plans to do so either due to the way docker-compose run
is designed.
There are other ways to achieve a similar result:
depends_on
directive to specify that the web
service depends on the backup
service (or vice versa). It may be useful to create a new docker-compose file for this.docker-compose up web backup
instead of docker-compose run
docker-compose run web; docker-compose run backup
web
and backup
services into a single service in your docker-compose.yml
.Version docker-compose version 1.29.2, build 5becea4c allows it using the sintax below:
docker-compose up -d SERVICE1 SERVICE2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With