简体   繁体   English

配置uwsgi.ini文件,以便DJango项目将在Docker容器中工作

[英]Configuring a uwsgi.ini file so that a DJango project will work within a Docker container

I am trying to set the uwsgi.ini file so that it will work with a docker container. 我正在尝试设置uwsgi.ini文件,以便它将与uwsgi.ini容器一起使用。

In the Dockerfile, I have exposed port 8888. Below are the pieces of the Dockerfile that are related to this problem: 在Dockerfile中,我公开了端口8888。以下是与此问题相关的Dockerfile片段

Dockerfile Docker文件

EXPOSE 8888

ENV DOCKER_CONTAINER=1

#CMD ["uwsgi", "--ini", "/code/uwsgi.ini"]  <<< right now, this is commented out

CMD ["/bin/bash"]

Above, the CMD to run the uwsgi.ini file is commented out because, for me, it did not work initially. 上面,注释掉了运行uwsgi.ini文件的CMD ,因为对我而言,它最初并不起作用。 I changed the CMD to "/bin/bash" so that I could log in to the OS level of the container. 我将CMD更改为“ / bin / bash”,以便可以登录到容器的OS级别。 After doing so, I then ran the code below: 这样做之后,我接着运行以下代码:

uwsgi --http 923b235d270e:8888 --chdir=/code/backendworkproj --module=backendworkproj.wsgi:application --env DJANGO_SETTINGS_MODULE=backendworkproj.settings --master --pidfile=/tmp/backendworkproj-master.pid --socket=127.0.0.1:49152 --processes=5 --uid=1000 --gid=2000 --harakiri=20 --max-requests=5000 --vacuum  

Once complete, I was able to go to port 8888 on the machine and see the website. 完成后,我可以转到机器上的端口8888并查看网站。

So, in short, everything worked. 因此,简而言之,一切正常。

The problem I am facing now is to convert the command above to something that will work in the uwgsi.ini file 我现在面临的问题是将上面的命令转换为可以在uwgsi.ini文件中使用的命令

If you look at part of the command above, I used : 如果您看上面命令的一部分,我使用了:

--http 923b235d270e:8888 --http 923b235d270e:8888

to specify a port. 指定端口。 The 923b235d270e is associated with the container (since 127.0.0.1 did not work) 923b235d270e与该容器关联(因为127.0.0.1无法正常工作)

How can I represent this (and env variables like DJANGO_SETTINGS_MODULE ) properly in the uwsgi file so that the server will work? 我该如何在uwsgi文件中正确表示此内容(以及诸如DJANGO_SETTINGS_MODULE之类的env变量),以便服务器正常工作? Below is the .ini file I have. 以下是我拥有的.ini文件。

TIA TIA

uwsgi.ini uwsgi.ini

[uwsgi] 
--http 923b235d270e:8888 
chdir=/code/backendworkproj 
module=backendworkproj.wsgi:application 
--env DJANGO_SETTINGS_MODULE=backendworkproj.settings 
master=True 
pidfile=/tmp/backendworkproj-master.pid 
socket=127.0.0.1:49152 
processes=5 
uid=1000 
gid=2000 
harakiri=20 
max-requests=5000 
vacuum=True

Never mind. 没关系。 This configuration worked. 此配置有效。

[uwsgi]
http-socket = :8888
chdir = /code/backendworkproj
module = backendworkproj.wsgi:application
env = DJANGO_SETTINGS_MODULE=backendworkproj.settings
master = True
pidfile = /tmp/backendworkproj-master.pid
socket = 127.0.0.1:49152
processes = 5
uid = 1000
gid = 2000
harakiri = 20
max-requests = 5000
vacuum = True

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

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