Sergei Basharov
Sergei Basharov

Reputation: 53920

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

Upvotes: 16

Views: 23400

Answers (3)

Blaise
Blaise

Reputation: 13489

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 and docker-compose run backup in another shell.
  • Merge the web and backup services into a single service in your docker-compose.yml.

Upvotes: 17

Denis Shcheglov
Denis Shcheglov

Reputation: 123

It may be more convenient for you to use profiles.

Upvotes: 2

Rafael Borja
Rafael Borja

Reputation: 4917

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

docker-compose up -d SERVICE1 SERVICE2

Upvotes: 6

Related Questions