Run python website on docker
I have created a Python + Flask website on docker. If I do “docker-compose up” the website is available on
I have tagged and pushed the container to docker and I tried doing
docker run mydomain/mycontainer from a different computer. It starts downloading everything, but at the end it displays
Status: Downloaded newer image for mydomain/mycontainer:latest and nothing happens.
I tried doing
docker run mydomain/mycontainer python app.py and it displays “Running on http://0.0.0.0:5000” but if I open that URL I get “This website is not available”. I cannot see any processes running on port 5000 either.
2 Solutions collect form web for “Run python website on docker”
0.0.0.0 is the local address inside the docker image. If you want to access it outside the image (ie. locally on your computer), you have to expose the given port. Here is the EXPOSE parameter documentation.
If you run the command:
docker run -p 5000:5000 mydomain/mycontainer python app.py
Your server will be accessible on:
BTW, I made a public (and open source) Docker image with all the bells and whistles that you can use to build a Python Flask web application.
It has uWSGI for running the application, Nginx to serve HTTP and Supervisord to control them, so you don’t have to learn how to install and configure all those to build your Python Flask web app.
It seems like uWSGI with Nginx is one of the more robust (and with great performance) ways to deploy a Python web app. Here are the benchmarks: http://nichol.as/benchmark-of-python-web-servers.
There are even some template projects you can use to bootstrap your own. And also, you don’t have to clone the full project or something, you can just use it as a base image.