Skip to content

Conversation

@SMFloris
Copy link

@SMFloris SMFloris commented Sep 19, 2020

Fixed the regression introduced in 1.27.0, by changing the resource.limits.cpus conversion to string in order to be compatible with docker stack deploy.

Steps to reproduce the issue:

Having the following docker-compose.yml file

version: '3.7'

services:
    api:
        image: busybox
        command: ['sleep', '10']
        deploy:
            resources:
                limits:
                    cpus: '1'
>#running the following from versions 1.27.0 to 1.28.0dev gives an error
>docker-compose -f docker-compose.yml config | docker stack deploy
services.api.deploy.resources.limits.cpus must be a string

After the fix, the command runs as expected.

Resolves #7774

@SMFloris
Copy link
Author

SMFloris commented Sep 20, 2020

I also noticed by diffing the json schema from docker-compose with the config schema used by docker stack deploy (https://github.com/docker/cli/blob/master/cli/compose/schema/data/config_schema_v3.9.json) that the resource.reservations.cpus values are also supposed to be strings so I changed the interpolation of those as well.

This is the first time I'm browsing through docker stack/docker-compose code, but is there any reason why there are two configs at all? Wouldn't it be safer/easier to have one primary config and one that extends the other in some way?

EDIT: in order to reproduce, use the following docker-compose.yml file:

version: '3.7'

services:
    api:
        image: busybox
        command: ['sleep', '10']
        deploy:
            resources:
                reservations:
                    cpus: 1
>#running the following from versions 1.27.0 to 1.28.0dev gives an error
>docker-compose -f docker-compose.yml config | docker stack deploy
services.api.deploy.resources.reservations.cpus must be a string

…docker stack deploy

Signed-off-by: Floris-Andrei Stoica-Marcu <floris.sm@gmail.com>
Signed-off-by: Floris-Andrei Stoica-Marcu <floris.sm@gmail.com>
@ulyssessouza
Copy link
Contributor

Already fixed by #7768

@gingerhot
Copy link

gingerhot commented Sep 30, 2020

Already fixed by #7768

@ulyssessouza I don't think so, please see #7774 carefully

@champ
Copy link

champ commented Nov 26, 2020

@ulyssessouza please consider reopening this issue,

As @gingerhot indicates with the issue #7774 although the schema supports strings again for deploy.resources.limits.cpus, docker-compose config is not consistent with the schema outputting a number if the original value is a string. This breaks compatibility with docker stack deploy.
However, docker-compose config works as expected for deploy.resources.reservations.cpus, conserving string values.

@ieugen
Copy link

ieugen commented May 3, 2021

I also have issues with this.

version: "3.9"
service:
....
      resources:
        limits:
          memory: 5g
          cpus: "4.0"
        reservations:
          memory: 3g
          cpus: "2.0"
 ./deploy.sh 
Generating .env file
Configuring stack compose file
Deploying dev stack
services.classifier.deploy.resources.limits.cpus must be a string

cat deploy.sh

#! /bin/bash
set -e

echo "Generating .env file"
cp .env.default .env
[ -f .env.dev ] && cat .env.dev >> .env

echo "Configuring stack compose file"
docker-compose --file stack.yml --env-file .env config > .stack.yml

echo "Deploying dev stack"
docker stack deploy --compose-file .stack.yml dev

cat .stack.yml

      resources:
        limits:
          cpus: 4.0
          memory: 5g
        reservations:
          cpus: '2.0'
          memory: 3g

@brunocascio
Copy link

Hi guys, I'm facing the same issue with cpus limits.

It's not related to reservations, It's related to limits.

as @ieugen mentioned above.

Is there any workaround without a hacky solution? I'm using compose version 1.29.2

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

Successfully merging this pull request may close these issues.

cpus value type in output of config command is not consistent in version 1.27.3

6 participants