2

Our team is new to running a micro-service ecosystem and I am curious how one would achieve conditionally loading docker containers from a compose, or another variable-cased script.

An example use-case would be. Doing front-end development that depends on a few different services. We will label those DockerA/D

Dependency Matrix

Feature1 - DockerA

Feature2 - DockerA and DockerB

Feature3 - DockerA and DockerD

I would like to be able to run something like the following

docker-compose --feature1

or

magic-script -service DockerA -service DockerB

Basically, I would like to run the command to conditionally start the APIs that I need.

I am already aware of using various mock servers for UI development, but want to avoid them.

Any thoughts on how to configure this?

2
  • We have a increasingly elaborate Python wrapper around docker-compose to support doing this locally, but for a first shot why not just write a script that accepts service names and passes them to docker-compose? for project in projects; do docker-compose up $project; .... Is this for local development or running in production? Commented Jan 19, 2018 at 18:30
  • Local dev only. All the production stuff has a CD pipeline with Kubernetes. Commented Jan 21, 2018 at 2:32

1 Answer 1

5

You can stop all services after creating them and then selectively starting them one by one. E.g.:

version: "3"

services:
    web1:
        image: nginx
        ports:
            - "80:80"
    web2:
        image: nginx
        ports:
            - "8080:80"
docker-compose up -d
    Creating network "composenginx_default" with the default driver
    Creating composenginx_web2_1 ... done
    Creating composenginx_web1_1 ... done
docker-compose stop
    Stopping composenginx_web1_1 ... done
    Stopping composenginx_web2_1 ... done

Now any service can be started using, e.g.,

docker-compose start web2
    Starting web2 ... done

Also, using linked services, there's the scale command that can change the number of running services (can add containers without restart).

Sign up to request clarification or add additional context in comments.

1 Comment

I like this. I am putting together a PoC to discuss on Monday. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.