2

I have a docker-compose file that will startup 6 different microservices. The way our docker-repository is setup prevents the use of the 'latest' tag so I am looking for a way to run a script before docker-compose pulls the microservice images, which will set environment variables in the scope of the docker-compose.yml file.

version: '3'
services:
  #Service 1
  svc1:
    image: some-snapshot.docker.privaterepo.com/some-service:${LATEST_SVC_TAG}
    container_name: service1
    ports:
      - "8080:8080"
  #Service 2
  svc2:
    image: some-snapshot.docker.privaterepo.com/some-service2:${LATEST_SVC2_TAG}
    container_name: service2
    ports:
      - "8081:8081"

1 Answer 1

3

I'm not sure you really need "a script". You can just run something like:

LATEST_SVC_TAG=1.1 LATEST_SVC2_TAG=2.5 docker-compose up -d

Alternately, you could place those into a .env file locally:

cat > .env <<EOF
LATEST_SVC_TAG=1.1
LATEST_SVC2_TAG=2.3
EOF

docker-compose up -d
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I wasn't clear, I need to be able to not hard-code the version numbers, and have this run on a CI server. i.e on a new push to master, pull down all the latest images for the other services and run some tests against them.
If you need this to run on your CI server, just make the versions parameters to your CI jobs and expose them into the CI environment. Or are you looking for a script that will list all the available versions of your images, inspect the tags, and figure out which one is the most recent, and use that one?

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.