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

Created on 22 Jun 2017  路  13Comments  路  Source: docker/cli

Description

This is basically reopening https://github.com/moby/moby/issues/32118

I'd like to use some variable substitutions in my docker-compose.yml to define how my stack should be deployed. However, some keys must be of a certain type, for instance integers.

Steps to reproduce the issue:

  1. Create a docker-compose file using variable substitution for port and replicas
> cat demo.yml
version: "3.3"
services:
  nc:
    image: alpine
    command: nc -lp1789
    ports:
      - "1789:1789"
    deploy:
      replicas: ${NC_REPLICAS:-1}
  1. Stack Deploy
> docker stack deploy --compose-file demo.yml foo

Describe the results you received:

> docker stack deploy --compose-file demo.yml foo
services.nc.deploy.replicas must be a integer

Describe the results you expected:
sdf

> NC_REPLICAS=2 docker stack deploy --compose-file demo.yml foo
service created
> docker service ls
ID                NAME                        MODE             REPLICAS          IMAGE
X                 foo_nc                      replicated        2/2               nc

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

Output of docker version:

Client:
 Version:      17.06.0-ce-rc5
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   b7e4173
 Built:        Tue Jun 20 07:14:13 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.0-ce-rc5
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   b7e4173
 Built:        Tue Jun 20 07:18:21 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

Containers: 89
 Running: 31
 Paused: 0
 Stopped: 58
Images: 282
Server Version: 17.06.0-ce-rc5
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: lvf5hvwinjbcoujab7jzw0tss
 Is Manager: true
 ClusterID: 7m5abn45bpvmdrp2ntqbayhm9
 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: 192.168.65.2
 Manager Addresses:
  192.168.65.2:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.31-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 2.933GiB
Name: moby
ID: DQ7K:NL44:CJT3:YYUR:M6TL:DSE4:ZIVL:DMY7:CJ4I:UVMQ:LDSB:U4HS
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 325
 Goroutines: 431
 System Time: 2017-06-21T20:36:14.592817654Z
 EventsListeners: 10
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

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

arestack areswarm kinenhancement versio17.06

Most helpful comment

Still having the same problem with docker-compose 3.7.

If like me you are trying to manage scaling by environment through env variables, I didn't find any solution except docker-compose.overrides or 'sed' script to replace the variable before docker stack deploy

All 13 comments

any ideas on when this will be available in a mainstream release?

it is in 17.11.0-ce but I guess 17.11.0-ce is an edge release.

I confirm 17.11 works with replica: "2" ( i did not tested earlier as I did not know about the progress)

Seems there's a regression in 18.04.0-ce, as I'm experiencing the issue in the latest boot2docker image.

$ docker stack deploy -c hello.yml hello
services.api.ports.0.published must be a integer
$ cat hello.yml
services:
    api:
        deploy:
            mode: replicated
            replicas: 3
            restart_policy:
                max_attempts: 3
        image: ushuz/hello:v1
        ports:
        -   published: '8080'
            target: '80'
version: '3.4'



md5-78e93e91fa1b7919a0399c0c18955345



$ docker version
Client:
 Version:   18.04.0-ce
 API version:   1.37
 Go version:    go1.9.2
 Git commit:    3d479c0
 Built: Tue Apr 10 18:14:11 2018
 OS/Arch:   linux/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:  18.04.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   3d479c0
  Built:    Tue Apr 10 18:23:35 2018
  OS/Arch:  linux/amd64
  Experimental: false

@ushuz thanks for reporting; unfortunately your comment got lost (as it was on a closed issue); I opened a new ticket instead https://github.com/docker/cli/issues/1073

Still having the same problem with docker-compose 3.7.

If like me you are trying to manage scaling by environment through env variables, I didn't find any solution except docker-compose.overrides or 'sed' script to replace the variable before docker stack deploy

I'm facing the same with 3.7 version:

Client:
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.13.8
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 23:42:35 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.8
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 22:48:33 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.3-0ubuntu2
  GitCommit:        
 runc:
  Version:          spec: 1.0.1-dev
  GitCommit:        
 docker-init:
  Version:          0.18.0
  GitCommit: 
docker-compose version 1.25.5, build 8a1c60f6
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

This is not resolved yet!

I am suffering from the same issue 馃槩

sample from compose file:

version: '3.0'
services:
  avs:
    image: myimage
    deploy:
      replicas: ${SCALE}
$ env | grep SCALE
SCALE=4
$ docker stack deploy -c ./docker-compose-stack.yml test
services.avs.deploy.replicas must be a integer

$ docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-162.git64e9980.el7_8.x86_64
 Go version:      go1.10.3
 Git commit:      64e9980/1.13.1
 Built:           Mon Jun 22 03:20:20 2020
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-162.git64e9980.el7_8.x86_64
 Go version:      go1.10.3
 Git commit:      64e9980/1.13.1
 Built:           Mon Jun 22 03:20:20 2020
 OS/Arch:         linux/amd64
 Experimental:    true

$ docker info
Containers: 6
 Running: 6
 Paused: 0
 Stopped: 0
Images: 34
Server Version: 1.13.1
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Authorization: rhel-push-plugin
Swarm: active
 NodeID: iv9g93qylmr6zlbafm12192yt
 Is Manager: true
 ClusterID: yfz3pn7uzdnvumptbxlt4lzj1
 Managers: 1
 Nodes: 4
 Orchestration:
  Task History Retention Limit: 3
 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.25.0.113
 Manager Addresses:
  172.25.0.113:2377
Runtimes: runc docker-runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version:  (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: 66aedde759f33c190954815fb765eedc1d782dd9 (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: fec3683b971d9c3ef73f284f176672c44b448662 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
 seccomp
  WARNING: You're not using the default seccomp profile
  Profile: /etc/docker/seccomp.json
Kernel Version: 3.10.0-957.el7.x86_64
Operating System: Red Hat Enterprise Linux
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 4
Total Memory: 15.5 GiB
Name: eqnycldoc01
ID: MHVE:GS7B:ZZTB:5T44:I7FG:VW5G:WYNQ:SBAF:2WYL:J5F2:5L6I:3CEX
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://registry.access.redhat.com/v1/
WARNING: bridge-nf-call-ip6tables is disabled
Experimental: true
Insecure Registries:
 eqnycldoc01:5000
 127.0.0.0/8
Live Restore Enabled: false
Registries: registry.access.redhat.com (secure), registry.redhat.io (secure), docker.io (secure), docker.io (secure)

@fpoulinSpiria @brunocascio @SayidHosseini @lrayman

I'm not able to reproduce the problem on a current version of Docker (19.03.13)

Steps I took to reproduce (note that I tried both version: "3.8" and version: "3.0" and both worked

mkdir repro-229 && cd repro-229

cat > docker-compose.yml <<'EOF'
version: "3.8"
services:
  web:
    image: nginx:alpine
    deploy:
      replicas: ${REPLICAS:-1}
EOF
docker stack deploy -c docker-compose.yml test

docker stack services test

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
jyo5girfghuu        test_web            replicated          1/1                 nginx:alpine

REPLICAS=3 docker stack deploy -c docker-compose.yml test
Updating service test_web (id: jyo5girfghuuiu67omg4y68la)

docker stack services test

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
jyo5girfghuu        test_web            replicated          3/3                 nginx:alpine

@lrayman Docker version 1.13.x is really old, and reached EOL over three Years ago. I suspect you're running the Red Hat fork of Docker, not the official packages (https://docs.docker.com/engine/install/). While there's currently no packages for RHEL specific, you should be able to install the CentOS packages. If you're not able to use the official Docker packages, I'd recommend opening a support ticket with Red Hat support.

Hey @thaJeztah,

Using ansible to inject vars you have to quote them, for example:

replicas: "{{ ansible_var.replicas | default(3) | int }}" # -> replicas: "3" and error thrown

Yes, if there's quotes around it, it will still produce an error;

mkdir repro-229 && cd repro-229

cat > docker-compose.yml <<'EOF'
version: "3.8"
services:
  web:
    image: nginx:alpine
    deploy:
      replicas: "3"
EOF
docker stack deploy -c docker-compose.yml test

services.web.deploy.replicas must be a integer

That looks like a separate issue; feel free to open a new ticket for that for discussion

@thaJeztah you are right!
The issue seems to have been resolved.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings