cli icon indicating copy to clipboard operation
cli copied to clipboard

env_file not working anymore in 'docker stack deploy'

Open kodyrecords opened this issue 2 years ago • 5 comments

Description

So far, it was possible to pass docker compose config output to docker stack deploy without problems, as follows: docker compose config | docker stack deploy -c - httpd

Now I upgraded to docker 25.0.4, and discovered corruption of env_file mapping. The tag is rendered as follows:

services:
  httpd:
    env_file:
      - path: /tmp/docker/httpd.env
        required: true

And as a result, the following error prevents startup: docker compose config | docker stack deploy -c - httpd

### Resulting error: services.httpd.env_file.0 must be a string

This is very critical, it currently blocks all of our deployments that have an env_file.

Reproduce

docker-compose.yml:

version: '3.8'
services:
  httpd:
    image: httpd:latest
    env_file:
      - ./httpd.env

httpd.env (content does not matter here):

SERVER_NAME=my-custom-server

Precondition: docker swarm init

Run: docker compose config | docker stack deploy -c - httpd

Expected behavior

The container should simply start.

docker version

Client: Docker Engine - Community
 Version:           25.0.4
 API version:       1.44
 Go version:        go1.21.8
 Git commit:        1a576c5
 Built:             Wed Mar  6 16:32:14 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.4
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       061aa95
  Built:            Wed Mar  6 16:32:14 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    25.0.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 4
  Running: 1
  Paused: 0
  Stopped: 3
 Images: 12
 Server Version: 25.0.4
 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: systemd
 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: j9wtq70drkn7uz09ve5cx7iru
  Is Manager: true
  ClusterID: 3kmynxgzfqluz4h5wv46zpu4j
  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: 127.0.0.1
  Manager Addresses:
   127.0.0.1:2377
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.5.0-25-generic
 Operating System: Ubuntu 23.10
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 62GiB
 Name: 
 ID: 
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: 
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

kodyrecords avatar Mar 19 '24 16:03 kodyrecords

Yes, looks like the latest additions to the compose spec to allow specifying this as required are backward incompatible (or at least how it normalizes it) 🤔

Does it work it you use docker stack config instead of docker compose config ? Or perhaps (depending on your use-case) it would even be possible to skip the intermediate compose config

thaJeztah avatar Mar 19 '24 19:03 thaJeztah

No I need to use it like as follows, example:

docker compose -f docker-compose.base.yml docker-compose.project.yml config | docker stack deploy -c - httpd

So I cannot use stack config.

The question is, what is causes this error here? Is it the additional "required: true" element?

kodyrecords avatar Mar 19 '24 20:03 kodyrecords

No I need to use it like as follows, example: docker compose -f docker-compose.base.yml docker-compose.project.yml config | docker stack deploy -c - httpd So I cannot use stack config.

Hm, but bothdocker stack config and docker stack deploy support multiple files, so I was curious why that didn't work; https://docs.docker.com/reference/cli/docker/stack/config/#examples

The question is, what is causes this error here? Is it the additional "required: true" element?

Yes; the schema used by docker stack deploy and previous versions of compose spec accepted a string (or array of strings) for env_file; this new format changes it to an array of objects/structs({ "path": <string>, "required": <bool>})

thaJeztah avatar Mar 19 '24 21:03 thaJeztah

I don't remember the needs exactly for using docker compose config instead of docker stack config, but I think it had to do with the fact that stack config relies on some older version or syntax, because it does not implement the compose-spec.

For example, it lacks the extends feature (https://github.com/moby/moby/issues/31101).

So I hope there will be a fix for `docker stack deploy' , similar to what has been done in a recent issue where also a compose change was not backwards compatible: https://github.com/docker/cli/issues/4859

kodyrecords avatar Mar 19 '24 21:03 kodyrecords

This is probably related to: https://github.com/docker/compose/issues/11591 https://github.com/docker/compose/issues/11598 https://github.com/docker/compose/pull/11604

In todays Docker 25.0.5 the issue is fixed.

But maybe you want to support the --no-interpolate mode in future?

kodyrecords avatar Mar 20 '24 12:03 kodyrecords