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

PythonDjangoUbuntuDockerDockerfile

Python Problem Overview


I'm building a new Docker image based on the standard Ubuntu 14.04 image.

Here's my 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

But if I open a shell when running the image, running python opens the interactive prompt as expected.

Why can't I invoke python through CMD in the Dockerfile?

Python Solutions


Solution 1 - Python

Use " instead of ' in CMD. (Documentation)

Solution 2 - Python

I have resolved my issue on my Mac by changing

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

to

CMD python app.py

Solution 3 - Python

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. Can use any online yaml validator.

Solution 4 - Python

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:

  1. Clear all unnecessary whitespace chars from Dockerfile
  2. Clear all cached images from this 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoe MorninView Question on Stackoverflow
Solution 1 - PythonAleksandr KovalevView Answer on Stackoverflow
Solution 2 - Pythonsrinivasa karadiView Answer on Stackoverflow
Solution 3 - PythonApoorva ManjunathView Answer on Stackoverflow
Solution 4 - PythonbauerenView Answer on Stackoverflow