Docker Community Forums

Share and learn in the Docker community.

Compose application not seeing variable substitutions


(Qadinc) #1

Hi all,

I’m trying to create a compose application with no hard coded values for IP addresses etc for the commands used in the containers. This compose file will be under source control so being generic is a plus as it could be used on several different cloud providers

For instance etcd is part of the application and it’s compose section looks like this:

version: '2’
services:
etcd:
image: quay.io/coreos/etcd
container_name: etcd
ports:
- “4001:4001”
- “2380:2380”
- "2379:2379"
volumes:
- /usr/share/ca-certificates/:/etc/ssl/certs
command: >
-name etcd0
-advertise-client-urls http://${HOSTNAME}:2379,http://${HOSTNAME}:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://${HOSTNAME}:2380
-listen-peer-urls http://0.0.0.0:2380
-initial-cluster-token etcd-cluster-1
-initial-cluster etcd0=http://${HOSTNAME}:2380
-initial-cluster-state new

However ${HOSTNAME} seems to evaluate to something like this looking at the command string in UCP:

-name etcd0 -advertise-client-urls http://8fe5bfdec0da:2379,http://8fe5bfdec0da:4001 -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -initial-advertise-peer-urls http://8fe5bfdec0da:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster-1 -initial-cluster etcd0=http://8fe5bfdec0da:2380 -initial-cluster-state new

I have confirmed using the export command that HOSTNAME and IP_ADDRESS are exported on the nodes

excerpt from command:
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE=“1000"
declare -x HOME=”/root"
declare -x HOSTNAME="example.mydomain.com"
declare -x IP_ADDRESS="xxx.xxx.xxx.xxx"
declare -x LANG=“en_US.UTF-8”

Each time I bring up the application, the HOSTNAME string above is different.

If I set and export something like IP_ADDRESS on the ucp node, but during deployment compose will state the variable cannot be found and will be set blank, tried double quotes around the variables in the compose file as well with the same result

I’m running the latest UCP with docker compose 1.1.1 Hardcoding the ip addresses of where this application will deployed in the compose file seems kinda pointless.

What am I doing wrong here?

Thanks


(Vivek Saraswat) #2

Does the same problem happen regardless of whether you are using the Compose UI or deploying from the CLI?


(Patrick Chanezon) #3

In the UCP admin UI, Try settings / scheduler / Allow Administrators to deploy containers on UCP controllers / check
Allow Users to deploy containers on UCP controllers check
Check both boxes and try deploying again.
This should have been fixed in 1.1.1, but 1.1.0 exhibited a similar issue with env variables not being set, associated to this setting.

P@


(Qadinc) #4

Yes, I’m mot able to get the variables to work when using docker-compose from command line with the same yaml file that is used in the UI, same issue.

I also have the 2 checkmarks that Patrick mentioned selected with no change in behavior.

Im trying some other tests on my local docker toolbox host to see if there are any differences.