How to use environment variables in docker compose -


i able use env variables inside docker-compose.yml, values passed in @ time of docker-compose up. example. doing today basic docker run command, wrapped around own script. there way achieve compose, without such bash wrappers?

proxy:   hostname: $hostname   volumes:     - /mnt/data/logs/$hostname:/logs     - /mnt/data/$hostname:/data 

  1. create template.yml, docker-compose.yml environment variable.
  2. suppose environment variables in file 'env.sh'
  3. put below piece of code in sh file , run it.

source env.sh; rm -rf docker-compose.yml; envsubst < "template.yml" > "docker-compose.yml";

a new file docker-compose.yml generated correct values of environment variables.

sample template.yml file:

oracledb:         image: ${oracle_db_image}         privileged: true         cpuset: "0"         ports:                 - "${oracle_db_port}:${oracle_db_port}"         command: /bin/sh -c "chmod 777 /tmp/start; /tmp/start"         container_name: ${oracle_db_container_name} 

sample env.sh file:

#!/bin/bash  export oracle_db_image=<image-name>  export oracle_db_port=<port exposed>  export oracle_db_container_name=oracle_db_server 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -