For development and debugging purposes sometimes we just need to start a particular service or a set of them. Here’s how is done.
Prerequisites
- Docker
- Docker Compose
Solution
To start only a particular service from a specific Docker Compose file when using multiple Docker Compose files, you can use the --file
\ -f
option followed by the path to the desired Docker Compose file. For instance:
docker compose up <service-name-1> <service-name-2>
However, if you have more than one docker compose stack this could get tricky. The thing is you can’t choose a particular service when using more than one docker compose file. Docker Compose does not support starting individual services from different compose files using the up command. The up command is designed to start all the services defined in a single Docker Compose file. The following example won’t work:
docker compose -f docker-compose-1.yml -f docker-compose-2.yml up <service-name-1>
So, either combine them into a single file first or spin them up as independent stack but create and share external network between them.
Conclusion
In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.