现在,我想按照以下简单的文档/教程创建一个容器,以在图像内运行虚拟命令:
https://docker-py.readthedocs.io/en/stable/containers.html#container-objects
import docker
client = docker.from_env()
client.containers.run(shm_size='1g',ulimits=[docker.types.Ulimit(name='memlock',hard=-1),docker.types.Ulimit(name='stack',hard=67108864)],image='ubuntu:16.04',auto_remove=True,command='date')
结果如下:
————————————————————————— ContainerError Traceback (most recent call
last) in ()
—-> 1 client.containers.run(shm_size=’1g’,ulimits=[docker.types.Ulimit(name=’memlock’,
docker.types.Ulimit(name=’stack’,
image=’ubuntu:16.04′,command=’date’)~/anaconda3/lib/python3.7/site-packages/docker/models/containers.py in
run(self,image,command,stdout,stderr,remove,**kwargs)
812 if exit_status != 0:
813 raise ContainerError(
–> 814 container,exit_status,out
815 )
816
尽管以下命令可以完美运行:
docker run --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 --rm -t ubuntu:16.04 "date"
我使用的选项组合有什么问题?
--ulimit
command flag的参数语法为:
<type>=<soft limit>[:<hard limit>]
并且文档说明:
Note: If you do not provide a hard limit,the soft limit will be used for both values. If no ulimits are set,they will be inherited from the default ulimits set on the daemon.
为了获得相同的行为,我将尝试将您的python ulimit声明更改为
docker.types.Ulimit(name='stack',soft=67108864,hard=67108864)]
这听起来像python documentation的缺点,它仅表示软参数和硬参数都是可选参数.