Skip to content

Instantly share code, notes, and snippets.

@pingiun
Last active May 14, 2021 22:41
Show Gist options
  • Save pingiun/1afa5e135ac50b40f02f44b2357948f8 to your computer and use it in GitHub Desktop.
Save pingiun/1afa5e135ac50b40f02f44b2357948f8 to your computer and use it in GitHub Desktop.

uwsgi python Dockefile

How to use this

You can use this dockerfile to run uwsgi in a docker container, then you can run nginx locally/ in another docker container and route requests trough a docker volume on the socket (e.g. /tmp/socket/uswgi.sock). Just place the dockefile in the same directory as your python uwsgi app. Then build the docker container and run with this command (where uwsgi-python is the name of the image):

docker run -d -e UWSGI_MOUNTPOINT=/ -e UWSGI_APP=app:app -v /tmp/socket:/app/socket uwsgi-python

I use the following nginx configuration with this container:

server {
	listen 80;

	location / {
		uwsgi_pass unix:///tmp/socket/uwsgi.sock;
		include uwsgi_params;
	}
}
FROM python:3
MAINTAINER Jelle Besseling <[email protected]>
COPY . /app
WORKDIR /app
RUN pip install uwsgi && pip install -r requirements.txt
VOLUME ["/app/socket/"]
ENV UWSGI_MOUNTPOINT /
ENV UWSGI_APP app:app
CMD /usr/local/bin/uwsgi -s /app/socket/uwsgi.sock --manage-script-name --mount $UWSGI_MOUNTPOINT=$UWSGI_APP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment