【问题标题】:Dockerize Django app failed with error "/bin/sh: [python3,: not found"Dockerize Django 应用程序失败,出现错误“/bin/sh: [python3,: not found”
【发布时间】:2021-07-04 03:48:02
【问题描述】:

我的 docker-compose 文件如下:

Django_2.2:
build:
  context: .
  dockerfile: Dockerfile_Build_Django
# Give an image name/tag
image: django_2.2:iot 
container_name: Django_2.2
depends_on: 
  - Django_Mongo_4.2.12
networks:
  sw_Django:
    ipv4_address: 192.168.110.12
ports:
  - 8000:80
restart: always
volumes: 
  - type: volume
    source: vol_django_codes
    target: /usr/src/app

我的 docker 文件“Dockerfile_Build_Django”如下:

FROM python:3.9.3-alpine3.13
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY . .
RUN pip install -r requirements.txt
# CMD ["python","./IoTSite/manage.py","runserver","0.0.0.0:80"]
CMD python ./IoTSite/manage.py runserver 0.0.0.0:80

requirements.txt 如下:只有 1 行

Django == 2.2.17

但是当我运行“docker-compose up”时,它失败并出现以下错误,

[root@Django]# docker logs Django_2.2 
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found
/bin/sh: [python3,: not found

我一直在寻找解决方案,并尝试了许多通过 google 找到的修复程序,到目前为止没有运气。任何帮助表示赞赏。 我觉得涉足 IT 是在浪费生命,因为根据指南/用户手册进行 5 分钟编码,然后花费数小时甚至数天进行故障排除......

【问题讨论】:

  • 是的,有时候是在浪费生命……能不能也把requirements.txt加进去?
  • 通常,如果您遇到该错误,那么您的 CMD 看起来像它具有 JSON 数组语法,但您的标点符号的某些部分错误(例如,单引号而不是双引号);参见例如 Docker image error: “/bin/sh: 1: [python,: not found”。但这与您在问题中包含的文件不匹配。
  • @Petronella,抱歉耽搁了,requirements.txt 已更新到帖子中。

标签: python-3.x django docker docker-compose


【解决方案1】:

如果可以的话,我的也有:

FROM python:3.8
ADD project /app
WORKDIR /app

#(for production only)
#RUN pip3 install --default-timeout=10 --no-cache-dir -r requirements.txt
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

EXPOSE 80
CMD ["gunicorn", "project.wsgi:application", "--bind", "0.0.0.0:80", "--reload"]

我建议您使用 gunicorn 在生产环境中运行您的服务器。

【讨论】:

  • 感谢分享,虽然我是 gunicorn 的新手。我会记住这一点。
猜你喜欢
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
  • 2020-01-28
  • 1970-01-01
  • 1970-01-01
  • 2015-12-02
  • 2018-06-06
  • 2019-09-11
相关资源
最近更新 更多