Docker 镜像错误:“/bin/sh: 1: [python,: not found”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32709075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Docker image error: "/bin/sh: 1: [python,: not found"
提问by Joe Mornin
I'm building a new Docker image based on the standard Ubuntu 14.04 image.
我正在构建一个基于标准 Ubuntu 14.04 镜像的新 Docker 镜像。
Here's my Dockerfile:
这是我的Dockerfile:
FROM ubuntu:14.04
RUN apt-get update -y
RUN apt-get install -y nginx git python-setuptools python-dev
RUN easy_install pip
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt # only 'django' for now
ENV projectname myproject
EXPOSE 80 8000
WORKDIR ${projectname}
CMD ['python', 'manage.py', 'runserver', '0.0.0.0:80']
When I try to run this image, I get this error...
当我尝试运行此图像时,出现此错误...
/bin/sh: 1: [python,: not found
/bin/sh: 1: [python,: 未找到
But if I open a shell when running the image, running python
opens the interactive prompt as expected.
但是如果我在运行图像时打开一个 shell,运行会python
按预期打开交互式提示。
Why can't I invoke python
through CMD
in the Dockerfile?
为什么我不能调用python
通过CMD
在Dockerfile?
采纳答案by Aleksandr Kovalev
Use "
instead of '
in CMD. (Documentation)
在 CMD 中使用"
而不是'
。(文档)
回答by srinivasa karadi
I have resolved my issue on my Mac by changing
我已通过更改在 Mac 上解决了我的问题
CMD ["python", "app.py"]
to
到
CMD python app.py
回答by Apoorva Manjunath
I had the same error. But in my case it was syntax error in command.
Had CMD ["python" "app.py"]
instead of CMD ["python", "app.py"]
我有同样的错误。但就我而言,它是命令中的语法错误。有CMD ["python" "app.py"]
而不是CMD ["python", "app.py"]
Validating the yaml file format can help in this case. Can use any online yaml validator.
在这种情况下,验证 yaml 文件格式会有所帮助。可以使用任何在线yaml 验证器。
回答by baueren
I had similar issue, but I didn't have any '
or "
chars in docker run command in my case.
But I found the solution to repair that issue and maybe will help you in similar case in future:
我有类似的问题,但在我的情况下,我在 docker run 命令中没有任何字符'
或"
字符。但是我找到了修复该问题的解决方案,将来可能会在类似情况下为您提供帮助:
- Clear all unnecessary whitespace chars from Dockerfile
- Clear all cached images from this Dockerfile
- Build and run new image
- 从 Dockerfile 中清除所有不必要的空白字符
- 清除此 Dockerfile 中的所有缓存图像
- 构建并运行新镜像
If you don't clear cached images, docker will use cached image with some crazy whitespace chars, which was created the same error message like the subject of the thread.
如果您不清除缓存图像,docker 将使用带有一些疯狂空白字符的缓存图像,这会创建与线程主题相同的错误消息。