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

V2 docker-compose config does not expose "Version", this breaks swarm deploys #8950

Closed
kaiomatico opened this issue Nov 22, 2021 · 8 comments

Comments

@kaiomatico
Copy link

Description

Docker-compose V2 does not expose the docker-compose.yml "Version" field when running docker-compose --file docker-compose.yml config. The older V1 version does expose this. This leads to failing docker swarm deployments as docker swarm then only reports the following:

docker stack deploy --with-registry-auth --compose-file <(docker-compose --file docker-compose.yml config) test
unsupported Compose file version: 1.0

We go the extra route through docker-compose because a docker stack deploy is not able to read .env files.

Steps to reproduce the issue:

  1. Install docker-compose V 2.1.1
  2. create the following docker-compose.yml:
version: "3.9"

services:
  nginx:
    image: nginx
  1. Run docker-compose --file docker-compose.yml config
  2. See that the field "Version" is missing
  3. Downgrade to docker-compose V 1.29.2
  4. See that the field "Version" is shown

Describe the results you received:
No version field (output from docker-compose V2.1.1):

services:
  nginx:
    image: nginx
    networks:
      default: null
networks:
  default:
    name: kaiomatico_default

Describe the results you expected:
A version field (output from docker-compose V1.29.2):

services:
  nginx:
    image: nginx
version: '3.9'

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

Output of docker compose version:

docker-compose version                         
Docker Compose version v2.1.1

Output of docker info:

docker info                                 
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 12
  Running: 0
  Paused: 0
  Stopped: 12
 Images: 122
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  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 logentries splunk syslog
 Swarm: active
  NodeID: n8ixd5o2ysna2u4jlcq4zrumm
  Is Manager: true
  ClusterID: w2ci3swewmwk66xyf61w6nrni
  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.178.21
  Manager Addresses:
   192.168.178.21:2377
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.13.0-21-generic
 Operating System: Ubuntu 21.10
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.34GiB
 Name: 9310
 ID: 4XPX:TVRF:3VTK:UXGZ:MAWV:34HV:5DLL:PIWQ:OLSV:S7JP:3RNK:2AR3
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: zisops
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details:

@ndeloof
Copy link
Contributor

ndeloof commented Nov 22, 2021

Docker Compose embrace the Compose Specification and doesn't set obsolete version attribute.
docker stack command is not compliant with the compose specification, see docker/cli#2527

@aaraney
Copy link

aaraney commented May 18, 2023

Having read this thread and others, it seems that the general mood about solving this problem within the docker stack cli is a bit grim. So, I wrote a compose-spec compliant docker-cli plugin replacement of docker stack deploy using compose-go that also does environment variable interpolation and handles .env files. Its called deployx!

@Erokos
Copy link

Erokos commented Mar 14, 2024

Can someone please explain why this issue is closed when the config command still doesn't work as it was supposed to? the compose version of 1.29 still does a better job at templating than the V2 version.

@ndeloof
Copy link
Contributor

ndeloof commented Mar 14, 2024

this issue is closed when the config command still doesn't work as it was supposed to

Depends what you consider "supposed to". Compose v2 conforms to the compose specification, docker stack doesn't

@Erokos
Copy link

Erokos commented Mar 14, 2024

When using compose version 1.29 for the config command with e.g. two compose files in which one extends the other, it outputs the final compose file correctly. Meaning, the syntax is correct with no version field missing and all other fields in the right places.
My question is, why can't we have the same behavior with the v2 version?

@luciangabor
Copy link

It might be easier to understand if you'd consider the new file format as a "V4" with the version implied by the absence of the version element (even if now it's just a rolling file format).

@ndeloof
Copy link
Contributor

ndeloof commented Mar 14, 2024

the syntax is correct with no version filed missing

This fiels is obsolete, it never guaranteed any kind of runtime compatibility, and was deprecated by the compose specification introduced in 2020

@Erokos
Copy link

Erokos commented Mar 14, 2024

Ok thanks for the clarifications and your time. I've tested the functionality and there were no problems.

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

No branches or pull requests

5 participants