我正在尝试将以下 docker run 命令转换为 python docker run:
docker run -v ${HOME}/mypath/somepath:/root/mypath/somepath:ro -v /tmp/report/:/root/report -e MY_VAR=fooname DOCKER_IMAGE
这就是我到目前为止所拥有的:
client = docker.from_env()
client.containers.run(DOCKER_IMAGE, 'MY_VAR=fooname', volumes={
f'{home}/mypath/somepath': {'bind': '/root/mypath/somepath', 'mode': 'ro'},
'/tmp/report': {'bind': '/root/report', 'mode': 'rw'},
},)
但似乎我在传递 env 变量时遇到了问题
docker.errors.APIError: 500 Server Error: Internal Server Error ("OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"MY_VAR=fooname\": executable file not found in $PATH": unknown")
传递环境变量的正确方法是什么?
编辑
改成之后
client.containers.run(DOCKER_IMAGE, None, environment=['MY_VAR=fooname'], volumes={
f'{home}/mypath/somepath': {'bind': '/root/mypath/somepath', 'mode': 'ro'},
'/tmp/report': {'bind': '/root/report', 'mode': 'rw'},
},)
我收到了这个错误:docker.errors.ContainerError: Command 'None' in image
docker build 文件中声明了只运行 python 脚本的命令。