Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose exclude service by default

If I have a great many services defined in a docker-compose project, how can I exclude a service from the default docker-compose up command?

For example, I have an nginx service, and an ssl service. They conflict because they both consume port 80, so how can I make it so that the ssl service doesn't start unless I specifically run that service, and by default the up command will do everything EXCEPT the ssl service?

like image 478
cclloyd Avatar asked Jun 14 '18 02:06

cclloyd


People also ask

How do I stop a specific service in docker compose?

There are two steps to stop a docker application containers: First, stop the running containers using docker-compose stop. Second, remove the stopped containers using docker-compose rm -f.

How do I run a docker compose file in detached mode?

Run Docker Compose in detached mode by passing the -d flag to docker-compose up . Use docker-compose ps to review what you have running.

Does docker compose down delete containers?

Description. Stops containers and removes containers, networks, volumes, and images created by up .

Does docker compose up rebuild images?

docker-compose up does everything so you have the option to rebuild. When you run docker-compose down it doesn't delete the image. You can delete that manually if you want.


1 Answers

Starting with docker-compose 1.28.0 the new service profiles are just made for that! With profiles you can mark services to be only started in specific profiles, for example:

services:   webapp:     # ...    nginx:     # ...     profiles: ["nginx"]     ports:       - 80:80    ssl:     # ...     profiles: ["ssl"]     ports:       - 80:80 
docker-compose up # start only your webapp services docker-compose --profile nginx up # start the webapp and nginx service docker-compose --profile ssl up # start the webapp and ssl service docker-compose run ssl # run the ssl service 

Depending on your exact use case/setup however it may be better to split your services into multiple docker-compose.yml files.

like image 147
acran Avatar answered Sep 16 '22 18:09

acran