“OSError: [Errno 8] Exec format error” when trying to run simple flask app in a docker container

后端 未结 2 2109
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 22:22

I\'m trying to start a simple Flask \"Hello world\" app in a docker container but I keep getting this error: \"OSError: [Errno 8] Exec format error: \'/app/app.py\'\"

My

2条回答
  •  不知归路
    2021-02-15 22:55

    Spent the entire day yesterday putting the pieces together on this problem, forum by forum, so I want to share a more detailed answer to this question. While building my image, I was also seeing the following warning message:

    SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host.

    "That warning was added, because the Windows filesystem does not have an option to mark a file as 'executable'. Building a linux image from a Windows machine would therefore break the image if a file has to be marked executable." - https://github.com/moby/moby/issues/20397

    So, as Richard Chamberlain points out in the comment above, adding "RUN chmod 644.py" ensures that the app.py file is properly marked.

    Putting all the pieces together, here is the complete Dockerfile that worked for me - Really hope it helps the next person struggling with this issue!

    FROM python:3.7-alpine
    COPY . /app
    WORKDIR /app
    RUN apk add --no-cache --virtual .build-deps \
        ca-certificates gcc postgresql-dev linux-headers musl-dev \
        libffi-dev jpeg-dev zlib-dev \
        && pip install --no-cache -r requirements.txt
    RUN chmod 644 app.py
    CMD ["python","app.py"]
    

提交回复
热议问题