E
E
Evgeny Serdyukov2019-02-25 13:15:23
ubuntu
Evgeny Serdyukov, 2019-02-25 13:15:23

What is the correct way to use environment for docker-compose?

I can't figure out if I can make my own idea.
There is an OSRM service that I want to run in a container. It has 2 important parameters, TAG, and the card it works with.
I want to use this data as parameters so that I can change it in 1 place, and you can switch to the new version, do not change it in commands, docker-compose files, etc.
I thought to do it through environment. Created a file osrm.env with the content:

OSRM_TAG=v5.22.0
OSRM_MAP=/maps/russia.osrm

Created docker-compose:
version: '2'
services:
 osrm:
  env_file:
   - ./osrm.env
  image: osrm/osrm-backend:${OSRM_TAG}
  volumes:
   - /home/djonik/maps:/maps
  ports:
   - "5000:5000"
  container_name: osrm-routed

  command: osrm-routed --algorithm mld ${OSRM_MAP}

Made export OSRM_TAG=v5.21.0to check which value will be used.
But with the docker-compose config command, I get the following output:
[email protected]:~/sedi-docker/osrm$ docker-compose config
WARNING: The OSRM_MAP variable is not set. Defaulting to a blank string.
services:
  osrm:
    command: 'osrm-routed --algorithm mld '
    container_name: osrm-routed
    environment:
      OSRM_MAP: /maps/ru_az_am_kg_ge_by_ua_cz.osrm
      OSRM_TAG: v5.22.0
    image: osrm/osrm-backend:v5.21.0
    ports:
    - 5000:5000/tcp
    volumes:
    - /home/djonik/maps:/maps:rw
version: '2.0'

Either I do not understand something correctly, or tell me how to do it better?
Or is it better not to use environment?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Zamyatin, 2019-03-07
@corw

If I remember correctly, the env config passed to the composer and the envs in the container itself are not related. Try passing the value of ${OSRM_TAG} to the env of the container:

environment:
  - OSRM_TAG=${OSRM_TAG}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question