Cli: docker stack deploy does not allow variable substitution for hostname

Created on 6 Dec 2017  路  2Comments  路  Source: docker/cli

Description

Similar to #229. In my case I'm wanting to use environment variable substitution for the hostname in the composer file deploy placement constraints.

Steps to reproduce the issue:

  1. Create a file named demo.yml with this content:
version: '3'
services:
  demo:
    deploy:
      placement:
        constraints:
          - node.hostname == ${TARGET_HOST}
      replicas: 1
    image: alpine

2.Run this:

TARGET_HOST=dev-rancheros && docker stack deploy -c demo.yml demo

Describe the results you received:

Creating service demo_demo
Error response from daemon: rpc error: code = 2 desc = value '' is invalid

Describe the results you expected:

Creating service demo_demo
> docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
e2g3qqzd093c        demo_demo           replicated          1/1                 alpine:latest  

Output of docker version:

Client:
 Version:      17.06.1-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   874a737
 Built:        Thu Aug 17 22:48:34 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.1-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   874a737
 Built:        Thu Aug 17 22:54:55 2017
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info:

Containers: 14
 Running: 0
 Paused: 0
 Stopped: 14
Images: 45
Server Version: 17.06.1-ce
Storage Driver: overlay
 Backing Filesystem: extfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: yvuh7jy2khr7kg6nikl65d8gc
 Is Manager: true
 ClusterID: q2r4gxr0gn02cfm9xwxe66j9t
 Managers: 1
 Nodes: 1
 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
  Force Rotate: 0
 Root Rotation In Progress: false
 Node Address: 10.0.2.15
 Manager Addresses:
  10.0.2.15:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.45-rancher
Operating System: RancherOS v1.1.0
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.861GiB
Name: dev-rancheros
ID: 4HSX:WUAM:RGRY:JK6K:LCAV:CYBP:LYNO:BEA2:JBQQ:RUFQ:IO7V:4ZX2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):
VirtualBox 5.1.22 r115126 on a macOS 10.13.1 host

areswarm versio17.06

Most helpful comment

I don't think this is the same idea as #229. In that case there was a validation error.

Your problem is this:

TARGET_HOST=dev-rancheros && docker stack deploy -c demo.yml demo

It should be

TARGET_HOST=dev-rancheros docker stack deploy -c demo.yml demo

or

export TARGET_HOST=dev-rancheros && docker stack deploy -c demo.yml demo

All 2 comments

I don't think this is the same idea as #229. In that case there was a validation error.

Your problem is this:

TARGET_HOST=dev-rancheros && docker stack deploy -c demo.yml demo

It should be

TARGET_HOST=dev-rancheros docker stack deploy -c demo.yml demo

or

export TARGET_HOST=dev-rancheros && docker stack deploy -c demo.yml demo

Ah. Did not realize the way I was calling docker would invalidate the variable.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings