Follow these steps, it shouldn't go wrong :
- First go ahead and create a file called
template.yml
, this file is basically going to be yourdocker-compose.yml,
with you environment variables. - Now create a file called 'env.sh' , your environment variables are going to be in this.
- Now run the below code in a .sh file.
source env.sh; rm -rf docker-compose.yml; envsubst < "template.yml" > "docker-compose.yml";
This will create a new docker-compose.yml file with all the right values of environment.
Here is a sample template.yml file given below:
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}
Here is a sample 'env.sh' file given below:
#!/bin/bash
export ORACLE_DB_IMAGE=<image-name>
export ORACLE_DB_PORT=<port to be exposed>
export ORACLE_DB_CONTAINER_NAME=ORACLE_DB_SERVER
Hope this helps :)
Want to get better in docker and it's related topics ? Try out docker training course.