docker / for-linux

Docker Engine for Linux
https://docs.docker.com/engine/installation/
756 stars 85 forks source link

Docker Swarm {{.Task.Slot}} returns {{.Node.ID}} value #1378

Open JeanneD4RK opened 2 years ago

JeanneD4RK commented 2 years ago

Expected behavior

~: printenv

X_NODE_HOSTNAME=XXXXXXXXXXXXXXX
X_NODE_ID=0m1ivou2kppkjlhwihy7divv9
X_NODE_PLATFROM={x86_64 linux}
X_NODE_PLATFROM_ARCHITECTURE=x86_64
X_NODE_PLATFROM_OS=linux
X_SERVICE_ID=yl3gd8zvpy6lybaeajuqjn658
X_SERVICE_LABELS=map[com.docker.stack.image:docker.elastic.co/elasticsearch/elasticsearch:7.17.0 com.docker.stack.namespace:diskover]
X_SERVICE_LABEL_CUSTOM=
X_SERVICE_LABEL_STACK_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:7.17.0
X_SERVICE_LABEL_STACK_NAMESPACE=elasticsearch
X_SERVICE_NAMES= elasticsearch
X_TASK_ID=mz7spdpjdv2dr3sfqlz2b2tmo
X_TASK_NAME=diskover_elasticsearch.0m1ivou2kppkjlhwihy7divv9.mz7spdpjdv2dr3sfqlz2b2tmo
X_TASK_SLOT=1

Actual behavior

~: printenv

X_NODE_HOSTNAME=XXXXXXXXXXXXXXX
X_NODE_ID=0m1ivou2kppkjlhwihy7divv9
X_NODE_PLATFROM={x86_64 linux}
X_NODE_PLATFROM_ARCHITECTURE=x86_64
X_NODE_PLATFROM_OS=linux
X_SERVICE_ID=yl3gd8zvpy6lybaeajuqjn658
X_SERVICE_LABELS=map[com.docker.stack.image:docker.elastic.co/elasticsearch/elasticsearch:7.17.0 com.docker.stack.namespace:diskover]
X_SERVICE_LABEL_CUSTOM=
X_SERVICE_LABEL_STACK_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:7.17.0
X_SERVICE_LABEL_STACK_NAMESPACE=elasticsearch
X_SERVICE_NAMES= elasticsearch
X_TASK_ID=mz7spdpjdv2dr3sfqlz2b2tmo
X_TASK_NAME=diskover_elasticsearch.0m1ivou2kppkjlhwihy7divv9.mz7spdpjdv2dr3sfqlz2b2tmo
X_TASK_SLOT=0m1ivou2kppkjlhwihy7divv9

Steps to reproduce the behavior

docker-compose.yml

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
    deploy:
      mode: global
    hostname: 'es{{.Task.Slot}}'
    environment:
      X_NODE_ID: '{{.Node.ID}}'
      X_NODE_HOSTNAME: '{{.Node.Hostname}}'
      X_NODE_PLATFROM: '{{.Node.Platform}}'
      X_NODE_PLATFROM_ARCHITECTURE: '{{.Node.Platform.Architecture}}'
      X_NODE_PLATFROM_OS: '{{.Node.Platform.OS}}'
      X_SERVICE_ID: '{{.Service.ID}}'
      X_SERVICE_NAMES: '{{.Service.Name}}'
      X_SERVICE_LABELS: '{{.Service.Labels}}'
      X_SERVICE_LABEL_STACK_NAMESPACE: '{{index .Service.Labels "com.docker.stack.namespace"}}'
      X_SERVICE_LABEL_STACK_IMAGE: '{{index .Service.Labels "com.docker.stack.image"}}'
      X_SERVICE_LABEL_CUSTOM: '{{index .Service.Labels "service.label"}}'
      X_TASK_ID: '{{.Task.ID}}'
      X_TASK_NAME: '{{.Task.Name}}'
      X_TASK_SLOT: '{{.Task.Slot}}'
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ./volumes/elasticsearch/data:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300

Output of docker version:

(Installed via apt)
~: docker version
Client:
 Version:           20.10.5+dfsg1
 API version:       1.41
 Go version:        go1.15.15
 Git commit:        55c4c88
 Built:             Sat Dec  4 10:53:03 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.5+dfsg1
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.15.15
  Git commit:       363e9a8
  Built:            Sat Dec  4 10:53:03 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.13~ds1
  GitCommit:        1.4.13~ds1-1~deb11u1
 runc:
  Version:          1.0.0~rc93+ds1
  GitCommit:        1.0.0~rc93+ds1-5+b2
 docker-init:
  Version:          0.19.0
  GitCommit:

Output of docker info:

~: docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 6
  Running: 2
  Paused: 0
  Stopped: 4
 Images: 2
 Server Version: 20.10.5+dfsg1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: 0m1ivou2kppkjlhwihy7divv9
  Is Manager: true
  ClusterID: mries0ljoqgrc873n8fqian4f
  Managers: 1
  Nodes: 3
  Default Address Pool: 10.0.0.0/8
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 10.216.0.197
  Manager Addresses:
   10.216.0.197:2377
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1.4.13~ds1-1~deb11u1
 runc version: 1.0.0~rc93+ds1-5+b2
 init version:
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.0-13-cloud-amd64
 Operating System: Debian GNU/Linux 11 (bullseye)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 31.36GiB
 Name: azeu1-diskover-docker1
 ID: YSN7:V7RP:Y645:K746:VG63:KMFI:K6WM:HBL4:XAOL:WHCI:INUA:OPUL
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  10.216.0.197:5000
  127.0.0.0/8
 Live Restore Enabled: false

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

3 nodes swarm in Azure

ross211 commented 2 years ago

You won't get a task slot of '1' in global deploy mode, try replicated mode.

povesteam commented 2 years ago

This is intended behaviour when you use deploy: mode: global, because this global mode instructs the swarm to start each task only once for each docker node.

The SlotTuple structure is defined and described here.