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

Compatibility mode #5684

Merged
merged 2 commits into from
Feb 26, 2018
Merged

Compatibility mode #5684

merged 2 commits into from
Feb 26, 2018

Conversation

shin-
Copy link

@shin- shin- commented Feb 17, 2018

Using the --compatibility CLI flag, v3 files can be converted to their v2 equivalent, with deploy options translated when possible. --compatibility can be used with all commands.

The conversion is a "best effort" attempt and shouldn't be relied on for production deployments.

Fixes #4513

translating deploy keys to equivalent v2 config if available

Enabled using `--compatibility` CLI flag

Signed-off-by: Joffrey F <[email protected]>
@shin- shin- added this to the 1.20.0 milestone Feb 17, 2018
@shin-
Copy link
Author

shin- commented Feb 17, 2018

cc @mefyl @vdemeester for review 👓

@thaJeztah
Copy link
Member

But doesn’t the V3 format already support memory and cpu limits? ie;

deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
        reservations:
          cpus: '0.25'
          memory: 20M

@thaJeztah
Copy link
Member

Oh; they were ignored by docker compose? Sorry, missed that

@shin-
Copy link
Author

shin- commented Feb 20, 2018

@thaJeztah Yes, the point here is to have a way to account for them in Compose as well. It's behind a flag because we can't really guarantee the behavior will match exactly what you would see with stack deploy. Does that make sense?

@dnephin
Copy link

dnephin commented Feb 21, 2018

Would it make sense make this an option on docker-compose config for converting a config from v3 to v2? That way you could inspect the changes to have some idea of what you're running.

@shin-
Copy link
Author

shin- commented Feb 21, 2018

@dnephin it works with config as well - it outputs a valid 2.3 file.

@thaJeztah
Copy link
Member

It's behind a flag because we can't really guarantee the behavior will match exactly what you would see with stack deploy. Does that make sense?

Wondering; things like configs and secrets already have a different implementation in docker-compose; if we document that there are differences, would it make sense to enable it by default (possibly an option to disable it)?

@shin-
Copy link
Author

shin- commented Feb 21, 2018

I want to say no - the secrets emulation is super confusing to users as it is already (see feedback in #4994 for example). I think having users opt into the feature gives us a chance to setup expectations a little better.

@thaJeztah
Copy link
Member

Ah, yes, then 👍 on the flag

@thiagolsfortunato
Copy link

thiagolsfortunato commented Jul 31, 2018

When I executed docker-compose --compatibility config` return this message:

WARNING: The following deploy sub-keys are not supported in compatibility mode and have been ignored: resources.reservations.cpus

deploy:
      resources:
        limits:
          memory: 1G
          cpus: '1'
        reservations:
          memory: 512M
          cpus: '0.50'

Why flag --compatibility does not support resources.reservations.cpus and resources.limits.cpus as memory ?!

@thaJeztah
Copy link
Member

Why flag --compatibility does not support resources.reservations.cpus and resources.limits.cpus equals memory ?!

Those options are scheduling options for swarm-mode services (i.e., they don't actually reserve the resources, only make swarm take those into account when scheduling containers on a node).

Docker Compose doesn't work with swarm mode (it deploys local containers), so there's no orchestrator to take those limits into account

@thiagolsfortunato
Copy link

thiagolsfortunato commented Jul 31, 2018

For not swarm-mode, how can I manager memory and cpu resources deploying local containers?

@thaJeztah
Copy link
Member

Using the feature described here; the warning that's printed is about cpu reservation;

Using this compose file:

version: '3.5'
services:
  web:
    image: nginx:alpine
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
docker-compose --compatibility up -d
WARNING: The following deploy sub-keys are not supported in compatibility mode and have been ignored: resources.reservations.cpus
Creating network "compat_default" with the default driver
Creating compat_web_1 ... done
docker inspect compat_web_1

...
    "Memory": 52428800,
    "NanoCpus": 500000000,
...

if 'cpus' in resources_dict['limits']:
service_dict['cpus'] = float(resources_dict['limits']['cpus'])
if 'reservations' in resources_dict:
service_dict['mem_reservation'] = resources_dict['reservations'].get('memory')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shin- I just noticed this; this part isn't correct, because --memory-reservation (although named similar) is something very different than --reserve-memory on docker service; see moby/moby#14579

@ZacharyBacon
Copy link

https://blog.csdn.net/ZacharyBacon/article/details/121739675 为何不通过cgroup限制资源,现在只是支持swarm模式下,如果是非swarm下,可以通过挂载cgroup的文件来限制容器的资源。感兴趣的话,可以看下我写的这篇文章。

@lordraiden
Copy link

So now "limits" cpu/memory can be used with compatibility mode in a v3 file
But "cpu_shares", "cpu_quota", "cpuset", "mem_limit" can not be used unless you use a v2 file
right?

@thaJeztah
Copy link
Member

@lordraiden this is a 6 year old pull request; docker compose v2 now uses the compose-specification file format which does not use a version, and unifies the v2 and v3 features; docs are located here; https://docs.docker.com/compose/compose-file/

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.

6 participants