Answer the question
In order to leave comments, you need to log in
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
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}
export OSRM_TAG=v5.21.0
to check which value will be used. [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'
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question