The latest tag is not supported - one of the tags above must be explicitly specified.
- This is because the tags represent different variants not incremental versions.
- This eliminates importing or pulling an unexpected version
Docker image with Nginx, uWSGI and Flask in a single container that enables running Python Flask Apps on NGINX.
NOTE: This project is a derivative of the project at tiangolo/UWSGI-NGINX-DOCKER, and was created ato address an urgent need for fixes and enhancements.
Implementing the enhancements required creating derivatives of both the base images and the flask images.
GitHub repo: https://github.com/robertpeteuil/docker-nginx-uwsgi-flask
Docker Hub image: https://hub.docker.com/r/robpco/nginx-uwsgi-flask/
This Docker image enables the creation of Python Flask Apps that run on Nginx by using uWSGI. It also simplifies the task of migrating a Flask-only App to run on Nginx, which is much more scalable for production deployments.
This image adds Flask support, Environment Variables and the ability to generated configuration details during startup to the underlying base image nginx-uwsgi.
The Docker-Hub repository contains auto-generated images from this repo: one for each Python version, and each one of those has a normal and Alpine-based image. These images can be referenced, or pulled, by using the image name with the tags listed above.
The image used in this repo includes the following enhancements (over previous repos):
- Adds image variants built on alpine-linux
- Ability to change Nginx listen port with a new LISTEN_PORT environment variable
- Updated built-in Nginx to 1.13.7 on non-alpine variants
- Reduces CRIT errors from
supervisordsupervisord.confis explicitly referenced via the Dockerfile CMD statementsupervisord.confincludes an explicitly set user-name
- Docker-Hub Image is Automatically re-built when Python updates
- Manually Building the image is protected against failures from key-server outages
Basic usage information is provided below. For full documentation with examples please visit the original repo: tiangolo/UWSGI-NGINX-DOCKER. If you reference the documentation on the original repo, remember to use this image robpco/nginx-uwsgi-flask to get the enhancements described above.
This image is normally as a base image for a project
This involves three high-level steps:
- Creating a
Dockerfilethat references this image:tag - Building an Image from that
Dockerfile - Running the Image and Testing the App
STEP 1 - Create a Dockerfile
- In this example, we use the
FROMline to specify this image and thepython3.6-alpinevariant - We copy our python scripts, in a sub-directory on the local computer called
app, to a folder in the container called/app.
FROM robpco/nginx-uwsgi-flask:python3.6-alpine COPY ./app /appSTEP 2 - Build an image from the Dockerfile
- Next we use the
docker buildcommand to create the image, name itmyappand tag it as version1
docker build -t myapp:1 . STEP 3 - Run the image and viewing the output
- Now, we can run the image and use a few extra parameters to make things easier
- The
-pparameter maps the localhost's port 8080 to port 80 of the image - The
-dparameterdetachesour terminal session from the image - The
--rmparameter automatically removes the image when it's stopped. - Finally, we specify the name
myappand tag1of the image
- The
- After running the command, we can open up out web-browser and type in
http://localhost:8080and interact with our Python Flask application
docker run --rm -p 8080:80 -d myapp:1 This image supports the following custom environment variables:
- UWSGI_INI - the path and file of the configuration info
- default:
/app/uwsgi.ini
- default:
- NGINX_MAX_UPLOAD - the maximum file upload size allowed by Nginx
- 0 = unlimited (image default)
- 1m = normal Nginx default
- LISTEN_PORT - custom port that Nginx should listen on
- 80 = Nginx default
The variables that begin with STATIC_ allow configuring Nginx to relay "static content" directly without going through uWSGI or Flask. This is advantageous for basic HTML pages, css and js files, that don't need their output adjusted by your Flask App.
- STATIC_INDEX - serve '/' directly from
/app/static/index.html- 0 = disabled (default)
- 1 = enabled - the file
index.htmllocated in the/app/staticdirectory (in the container) will be forwarded to any requests to the root of your server (/) will
- STATIC_URL - external URL where requests for static files originate
- STATIC_PATH - container location of static files (absolute path)
Environment variables can be set in multiple ways. The following examples, demonstrate setting the LISTEN_PORT environment variable via three different methods. These methods can be applied to any of the Environment Variables.
Setting in a Dockerfile
# ... (snip) ... ENV LISTEN_PORT 8080 # ... (snip) ...Setting during docker run with the -e option
docker run -e LISTEN_PORT=8080 -p 8080:8080 myimageSetting in docker-compose file using the environment: keyword in a docker-compose file
version: '2.2' services: web: image: myapp environment: LISTEN_PORT: 8080- 2017-11-29: Added ability to change port Nginx listens on with new environment variable
LISTEN_PORT.- Thanks to github user tmshn
- 2017-11-29: Alpine variants added
- Thanks to github user ProgEsteves
- 2017-11-29: Automatic image re-build when Python updates
- 2017-11-28: Updated Nginx version installed on non-Alpine images
- 2017:11-30: Alpine images - eliminated uWSGI random build failures
- 2017-11-30: Non-Alpine images - limit build failures caused by GPG key validation failing
- 2017-11-29: Alpine required additional changes:
- Replace default
/etc/nginx/nginx.confwith an alternate version - Create
/run/nginxdirectory to stop immediate Nginx crash
- Replace default
- 2017-11-28: Fixed console errors from supervisor process:
- Added explicit path reference to
supervisord.confin DockerfileCMDstatement - Added explicitly set username in
supervisord.conf
- Added explicit path reference to