gpt4 book ai didi

python - 按照教程进行:无法运行Django的Docker容器

转载 作者:行者123 更新时间:2023-12-02 20:46:21 25 4
gpt4 key购买 nike

我遵循this tutorial创建Django API并在docker上运行。
该API在没有docker的情况下运行良好,但是在docker上运行时遇到了问题。

本教程说,应该创建Dockerfile:

# Dockerfile

# FROM directive instructing base image to build upon
FROM python:2-onbuild

# COPY startup script into known file location in container
COPY start.sh /start.sh

# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000

# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
# done!

然后应该构建一个docker容器:
docker build -t davidsale/dockerizing-python-django-app .

到现在为止,一切正常。但是最后一条命令失败:
docker run -it -p 8000:8000 davidsale/djangoapp1

错误:
Starting Gunicorn.
[2018-11-01 19:24:16 +0000] [1] [INFO] Starting gunicorn 19.6.0
[2018-11-01 19:24:16 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2018-11-01 19:24:16 +0000] [1] [INFO] Using worker: sync
[2018-11-01 19:24:16 +0000] [7] [INFO] Booting worker with pid: 7
[2018-11-01 19:24:16 +0000] [7] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
ModuleNotFoundError: No module named 'helloworld.wsgi'
[2018-11-01 19:24:16 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-11-01 19:24:16 +0000] [1] [INFO] Shutting down: Master
[2018-11-01 19:24:16 +0000] [1] [INFO] Reason: Worker failed to boot.

只需提及我具有以下文件夹组织:
helloworld
- helloworld
- __init__.py
- wsgi.py
- settings.py
- urls.py
- views.py
- dbsqlite3
- manage.py
Dockerfile
requirements.txt
start.sh

最佳答案

您需要将项目目录添加到Docker镜像中。您正在关注的教程在dockerfile内容中有一个错误,并且其中没有任何WORKDIR变量:

# Dockerfile

# FROM directive instructing base image to build upon
FROM python:2-onbuild

# COPY startup script into known file location in container
COPY start.sh /start.sh

# Sets workdir
WORKDIR helloworld


# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000


# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
# done!

关于python - 按照教程进行:无法运行Django的Docker容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53108169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com