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

Question:

I am trying to set the uwsgi.ini file so that it will work with a docker container.

In the Dockerfile, I have exposed port 8888. Below are the pieces of the Dockerfile that are related to this problem:

Dockerfile

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. I changed the CMD to “/bin/bash” so that I could log in to the OS level of the container. 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.

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

If you look at part of the command above, I used :

–http 923b235d270e:8888

to specify a port. The 923b235d270e is associated with the container (since 127.0.0.1 did not work)

How can I represent this (and env variables like DJANGO_SETTINGS_MODULE ) properly in the uwsgi file so that the server will work? Below is the .ini file I have.

TIA

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
Asked By: Casey Harrils

||

Answers:

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
Answered By: Casey Harrils

If you use Django and uwsgi, don’t forget to set lazy-apps otherwise you will get database errors.

https://stackoverflow.com/a/29309598

Answered By: fireh
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.