portainer / portainer

Making Docker and Kubernetes management easy.
https://www.portainer.io
zlib License
30.74k stars 2.46k forks source link

compose files are misinterpreted as version 2 when there is no version header - and it's not possible to do anything with them #4943

Open lemmy04 opened 3 years ago

lemmy04 commented 3 years ago

Bug description I can't start, edit, or delete an old stack because the format is wrong

Expected behavior I would expect to be able to start, edit or delete an existing stack

Portainer Logs

2021/03/25 13:31:21 http error: Unable to stop stack (err=The Compose file '/data/compose/95/docker-compose.yml' is invalid because:

Unsupported config option for tk4: 'mem_reservation'

Steps to reproduce the issue:

  1. Go to any older stack that was created when portainer didn't support compose v2 syntax, it has to be one where the compose file does not specify the compose version, and with some statements that do not exist in other compose versions.
  2. try to do anything to it - stop, start, delete, edit
  3. It will not work. The error will complain about a syntax error since the default compose version seems to be 2 now, but the old compose file would be version 1 and have different commands.

Technical details:

Additional context according to the docker-compose documentation, a compose file without version header is interpreted as version 1 - but inside portainer it is misinterpreted as something else, most likely version 2, which breaks every pre-existing stack.

lemmy04 commented 3 years ago

here's my compose file:

tk4:
  mem_reservation: 96M
  mem_limit: 128M
  container_name: tk4
  hostname: akari
  image: rattydave/docker-ubuntu-hercules-mvs:latest
  net: bridge
  ports:
    - 3270:3270/tcp
    - 8038:8038/tcp
  privileged: true
  tty: true
  stdin_open: true
  restart: unless-stopped
  volumes:
    - /home/mathias/hercules_mode:/opt/hercules/tk4/unattended/mode
  environment:
    - NUMCPU=1
    - MAXCPU=1 

Up to portainer 2.0.x it worked fine - now in portainer 2.1.1 I can't do anythign with it, I can't start the stack, and without the stack running i can't edit the compose file either.

PortainerSupport commented 3 years ago

Ticket update by Bala Natarajan (bala.Natarajan@portainer.io)

Hi

pl confirm if the setup is on ARM/ARM64.

lemmy04 commented 3 years ago

nope, X86_64, docker running on openSUSE Leap 15.2

Anthony-Portainer commented 3 years ago

Remarking this for dev investigation. @lemmy04 , have you got any other log files you are able to sharE?

samdulam commented 3 years ago

I was able to deploy the above stack to Portainer v 2.0.0 but not into 2.1.1

I believe in 2.1.1 when a version is not specified, its interpreted as Version 3 (not 2). In this case the YML that 's used is not valid for Docker Compose Version 3

lemmy04 commented 3 years ago

portainer 2.5.1 - this bug is still around.

huib-portainer commented 3 years ago

Hi, you'll need to specify the version. (libcompose always assumes v2, but docker compose doesn’t)

But I assume that you can't edit the stack (to add the version in) because it's stopped?

lemmy04 commented 3 years ago

exactly. Also, the default behaviour for the docker-compose command is to "assume" Version 1 when there's no version info in a compose file, so I don't think portainer should deviate from that... and there is no way to "specify" version 1.

lemmy04 commented 3 years ago

It's even in the portainer logs:

2021/05/31 06:28:24 http error: Version in "/data/compose/25/docker-compose.yml" is invalid. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.

deviantony commented 3 years ago

@lemmy04 yes, we're going to work on https://github.com/portainer/portainer/issues/4944 which will allow you to update the version of a stopped stack to solve this problem.

cgi-psaunders commented 1 year ago

Since this ticket was opened, the version element has been deprecated. The compose specification has this to say:

Top-level version property is defined by the specification for backward compatibility but is only informative.

A Compose implementation SHOULD NOT use this version to select an exact schema to validate the Compose file, but prefer the most recent schema at the time it has been designed.

hanserasmus commented 1 year ago

I too have run into this issue now. And not sure how to fix it. Portainer version 2.18.4. Omitting the version, I get a notification unsupported Compose file version: 1.0. Which sucks, because I need to manipulate the startup order of containers. The depends_on keyword can be used in stack deploy on the latest compose version, according to Docker docs.

ThomasHineXYZ commented 5 months ago

Still an issue on 2.19.5