"docker-py mem_limit has been moved to host_config in API version 1.19" error
Hello, I'm trying to set up a Docker container in a Minion and getting this error on docker.installed
Comment: We did not get any expected answer from docker
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/modules/dockerio.py", line 640, in create_container
cpuset=cpuset
File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 237, in create_container
volume_driver
File "/usr/local/lib/python2.7/dist-packages/docker/utils/utils.py", line 546, in create_container_config
'mem_limit has been moved to host_config in API version 1.19'
InvalidVersion: mem_limit has been moved to host_config in API version 1.19
The error is being triggered in https://github.com/docker/docker-py/blob/master/docker/utils/utils.py#L544
if mem_limit is not None:
raise errors.InvalidVersion(
'mem_limit has been moved to host_config in API version 1.19'
)
So I got around it by adding "mem_limit: !!null" to my docker.installed:
app-container:
docker.installed:
...
- mem_limit: !!null
However, it'd be great to have this fixed. Thanks!
The minion has docker-py==1.3.0 installed and this is my master's versions report
$ salt --versions-report
Salt: 2015.5.2
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.10
ioflo: Not Installed
PyZMQ: 14.0.1
RAET: Not Installed
ZMQ: 4.0.4
Mako: 0.9.1
Debian source package: 2015.5.2+ds-1trusty1
Same error here, I guess it has something to do with a change in docker-py 1.3.0
A better workaround for now is just to install docker-py. 1.2.3, the previous version.
@hernanc, @jgelens, thanks for the report.
@jgelens docker 1.8 won't work with docker-py 1.2.3
The fix is actually a very simple one, instead of the default value of mem_limit being 0 it should be None.
Salts Code: https://github.com/saltstack/salt/blob/develop/salt/states/dockerio.py#L609 and https://github.com/saltstack/salt/blob/develop/salt/states/dockerio.py#L926
Docker Py Code that throws: https://github.com/docker/docker-py/blob/master/docker/utils/utils.py#L583
It should be fine since docker-py sets the default value of mem_limit to be None anyway.
Should also be fine in lower docker-py versions since it type checks the value of mem_limit: https://github.com/docker/docker-py/blob/1.2.3/docker/utils/utils.py#L510
FYI this fix doesn't seem to work with docker-py 1.3.1
>>> import docker
>>> docker.__version__
'1.3.1'
@dkiser, thanks for reporting. What error/conflict are you getting with that version?
@dkiser what version of docker are you running?
This fix works for me on docker 1.8.1 and docker-py 1.3.1
@krak3n @jfindlay I was using those exact versions. However, I was also passing a value for a memory limit in order to actually set it.
The fix maybe works if you leave mem_limit as none but as soon as you set it the error will trigger in the docker-py library. Was the goal of this fix to actually get mem_limit to work if a user provided values? If so we will have to add a version check and stuff the mem_limit into the host_config dict for version 1.19 of api or greater.
@dkiser ah ofc - I can try and get another PR in later. It is a rather annoying. Really docker-py should throw a warning that the value is no longer used rather than throwing an exception.
@krak3n agreed 8-). Another 2 lines of code should fix us up tho. Google up this error and the fix the ansible guys should work. We can just make a hosts dict and add the binds variable into it and then the mem_limit one only if that version check passes.
hey, what shall we do until the new version?
salt --versions-report
Salt: 2015.5.3
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.10
ioflo: Not Installed
PyZMQ: 14.0.1
RAET: Not Installed
ZMQ: 4.0.4
Mako: 0.9.1
Tornado: Not Installed
Debian source package: 2015.5.3+ds-1trusty1
pip list | grep docker
docker-py (1.3.1)
Using v2015.8.0rc4, I get the following failure when I attempt to get a container running.
"Failed to create new container: create_host_config() got an unexpected keyword argument 'mem_limit'"
I don't specify mem limit in my state file.
My state file is:
dummy.sls
dummylaunch:
dockerng.running:
- name: dockerserver
- image: myregistry/dummyserver:V123
- command: -m test
- network_mode: host
- restart_policy: on-failure:1
Here is the output from "sudo salt '*' dockerng.version"
vagrant-ubuntu-trusty-64:
----------
ApiVersion:
1.19
ApiVersionInfo:
- 1
- 19
Arch:
amd64
GitCommit:
786b29d
GoVersion:
go1.4.2
KernelVersion:
3.13.0-62-generic
Os:
linux
Version:
1.7.1
VersionInfo:
- 1
- 7
- 1
and the direct output from 'docker version'
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
Output from 'salt --versions-report'
Salt Version:
Salt: 2015.8.0rc4
Dependency Versions:
Jinja2: 2.7.2
M2Crypto: 0.21.1
Mako: 0.9.1
PyYAML: 3.10
PyZMQ: 14.0.1
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.4
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
gitdb: 0.5.4
gitpython: Not Installed
ioflo: Not Installed
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.3.0
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
python-gnupg: Not Installed
smmap: 0.8.2
timelib: Not Installed
System Versions:
dist: Ubuntu 14.04 trusty
machine: x86_64
release: 3.13.0-62-generic
system: Ubuntu 14.04 trusty
The deployment works fine if I disable the version line in module dockerng.py
if salt.utils.version_cmp(version()['ApiVersion'], '1.18') == 1:
hacked to
if salt.utils.version_cmp(version()['ApiVersion'], '1.99') == 1:
Thanks, @brasslock.
@hernanc that !!null work-around works great. Thanks.