简体   繁体   English

Docker 图像错误:“/bin/sh: 1: [python,: not found”

[英]Docker image error: "/bin/sh: 1: [python,: not found"

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?为什么我不能在Dockerfile中通过CMD调用python

在 CMD 中使用"而不是'(文档)

I have resolved my issue on my Mac by changing我已通过更改在 Mac 上解决了我的问题

CMD ["python", "app.py"]

to

CMD python app.py

I had the same error.我有同样的错误。 But in my case it was syntax error in command.但就我而言,它是命令中的语法错误。
I had a missing comma ","我少了一个逗号“,”
CMD ["python" "app.py"]
instead of代替
CMD ["python", "app.py"]

Validating the yaml file format can help in this case.在这种情况下,验证 yaml 文件格式会有所帮助。 Can use any online yaml validator .可以使用任何在线yaml 验证器

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 命令中没有任何'"字符。但我找到了修复该问题的解决方案,将来可能会在类似情况下为您提供帮助:

  1. Clear all unnecessary whitespace chars from Dockerfile从 Dockerfile 中清除所有不必要的空白字符
  2. Clear all cached images from this Dockerfile清除此 Dockerfile 中的所有缓存图像
  3. Build and run new image构建并运行新镜像

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 将使用带有一些疯狂空白字符的缓存图像,这会创建与线程主题相同的错误消息。

Well, I had the same issue, all I had to do was to add a comma between the elements in your CMD array.好吧,我遇到了同样的问题,我所要做的就是在 CMD 数组的元素之间添加一个逗号。

Most devs use visual studio code to write docker file and the official docker extension does not indicate an array if a comma is not added.大多数开发人员使用 Visual Studio 代码编写 docker 文件,如果不添加逗号,官方 docker 扩展名不会指示数组。

Also, use double quotes always.此外,始终使用双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM