Skip to content
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 Swarm deploy with array failed message #5159

Open
smilehappy126 opened this issue Jun 17, 2024 · 1 comment
Open

Docker Swarm deploy with array failed message #5159

smilehappy126 opened this issue Jun 17, 2024 · 1 comment

Comments

@smilehappy126
Copy link

Description

Hi,
I'm trying to deploy service dynamically under docker swarm mode by docker compose yml and some variables. Here's my docker compose yml ↓

version: '3.9'

services:
  web:
    build: ./sta_server
    restart: unless-stopped
    container_name: ${container_name} 
    environment:
      - serviceRootUrl=${serviceRootUrl}
      - http_cors_enable=${http_cors_enable}
      - http_cors_allowed.origins=*
      - persistence_db_driver=${persistence_db_driver}
      - persistence_db_username=${POSTGRES_USER}
      - persistence_db_password=${POSTGRES_PASSWORD}
      - persistence_db_url=${persistence_db_url}
      - persistence_autoUpdateDatabase=${persistence_autoUpdateDatabase}
    ports:
      - ${TOMCAT_PORTS_LOCAL}:${TOMCAT_PORTS_VIRTUAL}
      - ${TCP_PORTS_LOCAL}:${TCP_PORTS_VIRTUAL}
    depends_on:
      - test_swarm2_PG_ALIAS
    networks:
      - test_overlay_network
      
  test_swarm2_PG_ALIAS:
    image: postgis/postgis:latest
    restart: unless-stopped
    container_name: ${PGContainer_name}
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGDATA=/tmp
      - POSTGRES_HOST_AUTH_METHOD=${POSTGRES_HOST_AUTH_METHOD}
      - POSTGRES_INITDB_ARGS=${POSTGRES_INITDB_ARGS}
    ports:
        - ${PG_PORTS_LOCAL}:${PG_PORTS_VIRTUAL}
    volumes:
      - postgis_volume:/var/lib/postgresql/data/test_swarm2_PG_ALIAS
    networks:
      - test_overlay_network
      
volumes:
    postgis_volume:
networks:
  test_overlay_network:
    external: true

And when I execute docker stack deploy -c docker-compose.yml test_swarm2_stack I got some strange error ↓
services.web.ports array items[0,1] must be unique
Not sure if there's an issue with my yml.

Reproduce

  1. create yml
  2. docker stack deploy -c docker-compose.yml test_swarm2_stack

Expected behavior

No response

docker version

Client:
 Cloud integration: v1.0.35+desktop.13
 Version:           26.1.1
 API version:       1.45
 Go version:        go1.21.9
 Git commit:        4cf5afa
 Built:             Tue Apr 30 11:44:56 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.30.0 (149282)
 Engine:
  Version:          26.1.1
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.9
  Git commit:       ac2de55
  Built:            Tue Apr 30 11:48:04 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.31
  GitCommit:        e377cd56a71523140ca6ae87e30244719194a521
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    26.1.1
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0-desktop.1
    Path:     /Users/user/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0-desktop.2
    Path:     /Users/user/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.29
    Path:     /Users/user/.docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /Users/user/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.23
    Path:     /Users/user/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     /Users/user/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.1.0
    Path:     /Users/user/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/user/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.8.0
    Path:     /Users/user/.docker/cli-plugins/docker-scout

Server:
 Containers: 10
  Running: 5
  Paused: 0
  Stopped: 5
 Images: 150
 Server Version: 26.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: active
  NodeID: iv084svjmpm6jbob8sbe3xdt5
  Is Manager: true
  ClusterID: x5ay8bp6cpryphn80vzaewi5e
  Managers: 1
  Nodes: 1
  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: 192.168.65.3
  Manager Addresses:
   192.168.65.3:2377
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e377cd56a71523140ca6ae87e30244719194a521
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.6.26-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 8
 Total Memory: 7.657GiB
 Name: docker-desktop
 ID: 85a253ff-05c0-46ff-aa73-8d1a46b70a88
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/user/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Additional Info

No response

@camo-f
Copy link

camo-f commented Aug 23, 2024

Your YAML looks fine, it depends how you provide your variables. Values are probably empty because .env file is not loaded with docker stack deploy (unlike docker compose up, related issue with workarounds here: moby/moby#29133)

To properly load my vars, I use a .env file with export:

export ENV_VAR=value

Then I use source:

source .env && docker stack deploy -c docker-compose.yml my-stack

You can check your config beforehand with docker stack config -c docker-compose.yml

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

No branches or pull requests

2 participants