Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run more than one services with docker-compose in one command?

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
like image 264
Sergei Basharov Avatar asked Oct 11 '17 09:10

Sergei Basharov


People also ask

Can Docker container run multiple services?

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.

Can we run more than one application in Docker compose?

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).

Can we run multiple services on the same port in a Docker container?

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.


2 Answers

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:

  • Use the 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.
  • Use docker-compose up web backup instead of docker-compose run
  • Run it in separate commands like docker-compose run web; docker-compose run backup
  • Merge the web and backup services into a single service in your docker-compose.yml.
like image 156
Blaise Avatar answered Oct 11 '22 12:10

Blaise


Version docker-compose version 1.29.2, build 5becea4c allows it using the sintax below:

docker-compose up -d SERVICE1 SERVICE2
like image 22
Rafael Borja Avatar answered Oct 11 '22 12:10

Rafael Borja