New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker stack deploy ignores environment variables and replaces them with blank values #30251

Closed
samattridge opened this Issue Jan 18, 2017 · 6 comments

Comments

Projects
None yet
8 participants
@samattridge

samattridge commented Jan 18, 2017

Description

When using docker stack deploy against a docker-compose.yml file that contains environment variables for substitution, the environment variables are replaced with blank values.

Steps to reproduce the issue:

  1. Create a docker-compose.yml file containing at least one environment variable for substitution.
  2. Set the environment variables on the host.
  3. Run docker stack deploy --compose-file docker-compose.yml
  4. Run docker service inspect <servicename> on a service where you'd expect an environment variable to be substituted.

Describe the results you received:

The environment variables have been replaced with empty string values.

Describe the results you expected:

I would expect the command to either error if it isn't supported or I would expect it to replace the values in the compose file with the relevant environment variables.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Version:      1.13.0-rc7
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   48a9e53
 Built:        Fri Jan 13 06:52:01 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.0-rc7
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   48a9e53
 Built:        Fri Jan 13 06:52:01 2017
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info:

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 4
Server Version: 1.13.0-rc7
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 40
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: active
 NodeID: koz4efugm4ez6botqx48l1uzt
 Is Manager: true
 ClusterID: rshk2pdetaz31lmj5bkhvaqod
 Managers: 3
 Nodes: 6
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 172.21.0.68
 Manager Addresses:
  172.21.0.68:2377
  172.21.0.70:2377
  172.21.0.71:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
runc version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-47-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.359 GiB
Name: hidden
ID: 7JZL:TX5S:6FEL:D556:AJML:Y45S:QTKA:UFWD:3HES:QPMD:KLF4:SD2P
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: hidden
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Labels:
 provider=generic
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

Microsoft Azure VM

@djeeg

This comment has been minimized.

Show comment
Hide comment
@djeeg

djeeg Jan 22, 2017

Im running on Azure too and got clipped by this
Are you using sudo -E docker stack deploy to pass the env vars into sudo context?

djeeg commented Jan 22, 2017

Im running on Azure too and got clipped by this
Are you using sudo -E docker stack deploy to pass the env vars into sudo context?

@vdemeester

This comment has been minimized.

Show comment
Hide comment
@vdemeester

vdemeester Jan 23, 2017

Member

@samattridge could you share your docker-compose.yml file, because I can't reproduce.

$ cat docker-compose.yml
version: '3'
services:
  postgres:
    image: postgres:${TAG}
$ env TAG=9.3 docker stack deploy --compose-file docker-compose.yml foo
Removing service foo_postgres
Removing network foo_default
$ docker service ls
ID            NAME          MODE        REPLICAS  IMAGE
jxije1i67u2f  foo_postgres  replicated  1/1       postgres:9.3
$ docker stack rm foo
# […]
$ env TAG=9.4 docker stack deploy --compose-file docker-compose.yml foo
Removing service foo_postgres
Removing network foo_default
$ docker service ls
ID            NAME          MODE        REPLICAS  IMAGE
jxije1i67u2f  foo_postgres  replicated  1/1       postgres:9.4

It does environment variable substitution on my 1.13 daemon.

Member

vdemeester commented Jan 23, 2017

@samattridge could you share your docker-compose.yml file, because I can't reproduce.

$ cat docker-compose.yml
version: '3'
services:
  postgres:
    image: postgres:${TAG}
$ env TAG=9.3 docker stack deploy --compose-file docker-compose.yml foo
Removing service foo_postgres
Removing network foo_default
$ docker service ls
ID            NAME          MODE        REPLICAS  IMAGE
jxije1i67u2f  foo_postgres  replicated  1/1       postgres:9.3
$ docker stack rm foo
# […]
$ env TAG=9.4 docker stack deploy --compose-file docker-compose.yml foo
Removing service foo_postgres
Removing network foo_default
$ docker service ls
ID            NAME          MODE        REPLICAS  IMAGE
jxije1i67u2f  foo_postgres  replicated  1/1       postgres:9.4

It does environment variable substitution on my 1.13 daemon.

@samattridge

This comment has been minimized.

Show comment
Hide comment
@samattridge

samattridge Jan 26, 2017

@vdemeester Thanks for looking at this issue. I've just been through my tests again so I could send you a docker-compose file and I can't reproduce it now either. I must have been doing something wrong before. I'm so sorry to have wasted your time.

samattridge commented Jan 26, 2017

@vdemeester Thanks for looking at this issue. I've just been through my tests again so I could send you a docker-compose file and I can't reproduce it now either. I must have been doing something wrong before. I'm so sorry to have wasted your time.

@cecchisandrone

This comment has been minimized.

Show comment
Hide comment
@cecchisandrone

cecchisandrone Feb 28, 2017

For me it works in this case:

mysql:
    environment:
    - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    - MYSQL_DATABASE=${MYSQL_DATABASE}
    - MYSQL_USER=${MYSQL_USER}
    - MYSQL_PASSWORD=${MYSQL_PASSWORD}

but not in this case:

  rabbitmq:
    environment:
    - RABBITMQ_DEFAULT_USER
    - RABBITMQ_DEFAULT_PASS

Obviously I defined the env vars in all of the Swarm machines.
Is this normal?

cecchisandrone commented Feb 28, 2017

For me it works in this case:

mysql:
    environment:
    - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    - MYSQL_DATABASE=${MYSQL_DATABASE}
    - MYSQL_USER=${MYSQL_USER}
    - MYSQL_PASSWORD=${MYSQL_PASSWORD}

but not in this case:

  rabbitmq:
    environment:
    - RABBITMQ_DEFAULT_USER
    - RABBITMQ_DEFAULT_PASS

Obviously I defined the env vars in all of the Swarm machines.
Is this normal?

@tjlytle

This comment has been minimized.

Show comment
Hide comment
@tjlytle

tjlytle Mar 13, 2017

I'm seeing the same behavior as @cecchisandrone.

With this command:
BUILD_ENV=dev docker stack deploy -c docker-compose.yml --with-registry-auth my_stack

A config like this will not set the environment variables on the container:

environment:
      - BUILD_ENV

However, a config like this will work:

environment:
      - BUILD_ENV=${BUILD_ENV}

tjlytle commented Mar 13, 2017

I'm seeing the same behavior as @cecchisandrone.

With this command:
BUILD_ENV=dev docker stack deploy -c docker-compose.yml --with-registry-auth my_stack

A config like this will not set the environment variables on the container:

environment:
      - BUILD_ENV

However, a config like this will work:

environment:
      - BUILD_ENV=${BUILD_ENV}
@dnephin

This comment has been minimized.

Show comment
Hide comment
@dnephin

dnephin Mar 14, 2017

Member

I believe this will be fixed by #30781

Member

dnephin commented Mar 14, 2017

I believe this will be fixed by #30781

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment