This directory provides a Dockerfile to containerize your Python Flask application for both development and production use. This example uses Flask as the web framework, but you can modify it to fit your needs.
1. Dockerfile
- This file uses
python:alpine
as the base image and installs Flask and dependencies manually.
- This version uses
python:slim
as the base image to reduce the size of the image while still supporting Flask.
Here’s a comparison of the image sizes. The .slim
images are built using Docker Slim.
Copy the .dockerignore
file to the root of your project.
Create a Dockerfile in the root of your project. This file contains the necessary commands to build the Docker image.
docker build -t python_flask .
docker build -f Dockerfile_python_slim -t python_flask .
We can use Docker Slim to reduce the size of the image further.
Note: Docker Slim can remove some files that are required for your application to run. It is recommended to test the application thoroughly after using Docker Slim to ensure everything works as expected.
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock dslim/slim build --target python_flask
Once the image is built, run the container with:
docker run -p 5000:5000 python_flask
If you have suggestions or enhancements for this Docker setup, feel free to open a pull request.