Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude service on docker-compose up, docker-compose rm, etc #1294

Closed
olalonde opened this issue Apr 15, 2015 · 24 comments
Closed

Exclude service on docker-compose up, docker-compose rm, etc #1294

olalonde opened this issue Apr 15, 2015 · 24 comments

Comments

@olalonde
Copy link

@olalonde olalonde commented Apr 15, 2015

I have a service that I just need to run once (dc run createdbs):

createdbs:
  image: postgres:9.3
  links:
    - db
  command: >
    /bin/bash -c "
      psql --host=db --username=postgres -c 'CREATE DATABASE testnet;';
      psql --host=db --username=postgres -c 'CREATE DATABASE livenet;';
    "

Is it possible to not have it launched every time I run docker-compose up? I have looked at alternatives for creating the databases, but I'd rather not have separate file(s) just for this.

@hadim

This comment has been minimized.

Copy link

@hadim hadim commented Apr 18, 2015

The feature would be really usefull for different things :

  • database init
  • restore application
  • backup
  • ...
@olalonde

This comment has been minimized.

Copy link
Author

@olalonde olalonde commented Apr 18, 2015

I've solved my problem by using the docker-compose up myservice command instead which automatically only launches myservice's dependencies. I realised I actually never really need to do a docker-compose up.

@neg3ntropy

This comment has been minimized.

Copy link

@neg3ntropy neg3ntropy commented May 6, 2015

+1

@inka

This comment has been minimized.

Copy link

@inka inka commented May 26, 2015

would like and use that too. +1
(like vagrant autostart: false)

@igr

This comment has been minimized.

Copy link

@igr igr commented Jun 22, 2015

👍

@dnephin dnephin added the area/cli label Oct 27, 2015
@dnephin dnephin changed the title Exclude service on docker-compose up Exclude service on docker-compose up, docker-compose rm, etc Jan 15, 2016
@dnephin

This comment has been minimized.

Copy link
Contributor

@dnephin dnephin commented Jan 15, 2016

The current options are the list the services in the up command, or split the services between multiple compose files, and only specify some of them when running some commands.

@schickling

This comment has been minimized.

Copy link

@schickling schickling commented Mar 9, 2016

This would be a great addition 👍

@shane-axiom

This comment has been minimized.

Copy link

@shane-axiom shane-axiom commented Jun 3, 2016

+1, would really facilitate flexible executions of an app's components using a single docker-compose.yml file (e.g. fire up all components by default, but exclude a specific component when developing against it).

@SvenNederhoff

This comment has been minimized.

Copy link

@SvenNederhoff SvenNederhoff commented Jul 12, 2016

This would be a great addition 👍

@s-geissler

This comment has been minimized.

Copy link

@s-geissler s-geissler commented Jul 21, 2016

This would be a great thing to have!

@CybotTM

This comment has been minimized.

Copy link

@CybotTM CybotTM commented Jul 26, 2016

duplicates #1896

@dnephin

This comment has been minimized.

Copy link
Contributor

@dnephin dnephin commented Jul 27, 2016

Yes, I think this is covered by #1896.

In general I think trying to exclude services is not going to fit well with the design of Compose. Almost all the uses cases that require this are actually trying to do something like "build automation" not actually running services.

I've been working on a prototype of a tool designed for that purpose. dobi integrates with Compose, so you can do thing adhoc/admin/initialize tasks outside of the docker-compose.yml.

@dnephin dnephin closed this Jul 27, 2016
@pvledoux

This comment has been minimized.

Copy link

@pvledoux pvledoux commented Jun 14, 2017

My use case is excluding one (or more) services from the log output.

Something like this would great:

docker-compose logs -f --tail=100 service1 service2 -service3

@JoeJasinski

This comment has been minimized.

Copy link

@JoeJasinski JoeJasinski commented Aug 26, 2017

This would be particularly useful for moving from dev to production. In dev, it's great to be able to spin up all the services, including things like postgres, or elasticsearch. However, in prod, (or when deving against existing external services), it would be nice to prevent docker-compose from spinning up certain services via a docker compose override file or production file. Maybe this is possible with swarm?

@TMiguelT

This comment has been minimized.

Copy link

@TMiguelT TMiguelT commented Mar 21, 2018

Can we not just scale it down to zero? e.g.

docker-compose up --scale service3=0

This starts all the services except service3

@happilymarrieddad

This comment has been minimized.

Copy link

@happilymarrieddad happilymarrieddad commented Jul 21, 2018

docker-compose -f docker-compose.yaml up | grep "<name of service you are trying to bring up"

yeah... thumbs down when it works... and it's in a ton of docs...

@derianpt

This comment has been minimized.

Copy link

@derianpt derianpt commented Oct 3, 2018

Can we not just scale it down to zero? e.g.

docker-compose up --scale service3=0

This starts all the services except service3

This is great!

@foxmulder900

This comment has been minimized.

Copy link

@foxmulder900 foxmulder900 commented Nov 20, 2018

Can we not just scale it down to zero? e.g.

docker-compose up --scale service3=0

This starts all the services except service3

The down side to this approach is that the image for the service you are trying to skip will still be downloaded if it does not already exist. It would still be nice for a more official solution for this.

@nickjj

This comment has been minimized.

Copy link

@nickjj nickjj commented Jan 4, 2019

I would really like to see an official enabled: false property be added to a service (which defaults to true) because none of the above workarounds are viable in all use cases.

A real use case would be running a webpack watcher in development for assets. This might end up being a ~400-500mb image. Totally useful in development, but very wasteful in production. In production, not only would I not want it to run, but I wouldn't want Docker Compose to build or pull this image.

All of the above workarounds still involve building or pulling the image as stated by @foxmulder900.

But with full support at the property level, Docker Compose could skip everything about that service and then it can be controlled with variable substitution. Such as enabled: ${WEBPACK_SERVICE_STATE} and now both environments can use the same compose file.

@mikeerickson

This comment has been minimized.

Copy link

@mikeerickson mikeerickson commented Jan 4, 2019

I think this would be a terrific addition. I have done some rather hacky things to implement this in the past, but a flag would be pretty awesome

@worc

This comment has been minimized.

Copy link

@worc worc commented Jan 11, 2019

Can we not just scale it down to zero? e.g.

docker-compose up --scale service3=0

This starts all the services except service3

The down side to this approach is that the image for the service you are trying to skip will still be downloaded if it does not already exist. It would still be nice for a more official solution for this.

and the downside to downloading is sometimes your ci/cd doesn't have permissions for that image at that stage anyways. so you still get an error for trying to pull the image, even if you were ultimately going to scale it to zero.

@mXaln

This comment has been minimized.

Copy link

@mXaln mXaln commented May 1, 2019

My approach was to create a text file that has all the services in it to run (one line, space separated).
For example, create file services.txt that contains: db web sentry python
Then run
docker-compose up $(< services.txt)

only services listed in the file will run.

@Al81RU

This comment has been minimized.

Copy link

@Al81RU Al81RU commented Sep 12, 2019

$exclude_services = "service1", "service2", "service3"
$service_names = docker-compose config --services | Sort-Object| Where-Object { $exclude_services -notcontains $_ }
docker-compose up -d $service_names

@Max-Leopold Max-Leopold mentioned this issue Sep 17, 2019
@dnk8n

This comment has been minimized.

Copy link

@dnk8n dnk8n commented Apr 1, 2020

Interesting that when I have env_file defined in service_a but all I want to do is, docker-compose up service_b, I get:

ERROR: Couldn't find env file: ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.