One way to achieve this is to define your additional service in another file. Then, to start the additional service, run:
$ docker-compose -f docker-compose.yml -f optional-service.yaml up
For example, if I have a docker-compose.yml file that looks like this:
version: '2.1' services: lb: image: nginx:1.13 db: image: redis:3.2.9
I can expand it with option-service.yml, which looks like this:
version: '2.1' services: busy: image: busybox
Note that both compound files must use the same version of the compound file.
You can read more about this in the Compose documentation .
source share