Running Flask API Application container with Gunicorn and Nginx on Podman | Medium

A short information to creating in Flask

Photograph by Bluewater Sweden on Unsplash

We’ve already established how we might need our software to be structured as per this story. I’ve improved the code on how the applying consumes database credentials. Flask makes use of a built-in dev server when operating domestically, which isn’t recommended for manufacturing.

You need to configure a WSGI server for the applying to serve manufacturing visitors. There are a number of WSGI servers out there, however I’ve chosen Gunicorn resulting from its maturity. Nevertheless, Gunicorn is just not primarily made to serve static content material and graphics. As an alternative of labouring Gunicorn with these duties, we must always let the HTTP boss within the trade, Nginx, deal with all of the visitors requests and cargo balancing as a reverse proxy.

We are going to subsequently have two containers operating facet by facet in a podman pod and visitors will get to the applying container through Nginx.

Beneath, the Dockerfile will create the applying picture primarily based on ubi/python38 picture and when run, the gunicorn server shall be launched as outlined within the appentry.sh file.

The Nginx server should be configured to ship visitors to the applying container. Within the Nginx config file, embrace configs to inform Nginx to ship all visitors acquired through/path to gunicorn server at port 8000. These configs will then be added to the Nginx picture as per the Dockerfile.

We’ve the code base and Dockerfiles for each govt_structure software and Nginx. We are going to create a pod uncovered on port 8181 and deploy the applying containers to the pod. Run the next script to carry out these duties:

Lastly, our software is up and operating and may be examined at http://localhost:8181/sayhello (/sayhello simply returns a message).

Thanks for studying. You could find the complete code in my GitHub repo in govt department.

Maintain an eye fixed at on the next:

  • Pipfile content material
  • Redhat registry to tug ubi8/python-38 base picture
  • Database credentials are usually not dedicated in git
  • use podman logs <containername> to examine logs in case the container crashes

More Posts