Sometimes, we want to deploy a minimal Python Flask app in Docker.
In this article, we’ll look at how to deploy a minimal Python Flask app in Docker.
How to deploy a minimal Python Flask app in Docker?
To deploy a minimal Python Flask app in Docker, we create a Dockerfile in our Flask project directory.
For instance, we write
FROM dreen/flask
MAINTAINER dreen
WORKDIR /src
RUN mkdir -p /src
COPY . .
EXPOSE 5000
CMD ["python", "index.py"]
in our Dockerfile.
Then in index.py
, we write
# ...
if __name__ == '__main__':
app.run(host='0.0.0.0')
to run the app and expose it to all computers in the local network so that it can be served over the Internet.
Then we run
sudo docker run -i -p 5000:5000 -d my-project
to create the Docker image from the Flask project which is in the my-project
directory with the Dockerfile inside.
Conclusion
To deploy a minimal Python Flask app in Docker, we create a Dockerfile in our Flask project directory.