A small Python Docker image based on Alpine Linux. The image is only 225 MB and it includes python3-dev.
- 2.7 (Dockerfile)
- 2.7-onbuild (Dockerfile)
- 3.4 (Dockerfile)
- 3.4-onbuild (Dockerfile)
NOTE: onbuild images install the requirements.txt of your project from the get go. This allows you to cache your requirements right in the build. Make sure you are in the same directory of your requirements.txt file.
The default docker python images are too big, much larger than they need to be. Hence I built this simple image based on docker-alpine, that has everything needed for the most common python projects - including python3-dev (which is not common in most minimal alpine python packages).
REPOSITORY TAG VIRTUAL SIZE
jfloff/alpine-python 3.4 225.7 MB
python 3.4 685.5 MB
python 3.4-slim 215.1 MB
We actually get the same size as python:3.4-slim but with python3-dev installed (that's around 55MB).
Perhaps this could be even more smaller, but I'm not an Alpine guru. Feel free to post a PR.
This image runs python command on docker run. You can either specify your own command, e.g:
docker run --rm -ti jfloff/alpine-python python hello.pyOr extend this images using your custom Dockerfile, e.g:
FROM jfloff/alpine-python:3.4-onbuild
# for a flask server
EXPOSE 5000
CMD python manage.py runserverDont' forget to build your image:
docker build --rm=true -t jfloff/app .You can also access bash inside the container:
docker run --rm -ti jfloff/alpine-python /bin/bashPersonally, I build an extended Dockerfile version (like shown above), and mount my specific application inside the container:
docker run --rm -v "$(pwd)":/home/app -w /home/app -p 5000:5000 -ti jfloff/app- Installs
python-devallowing the use of more advanced packages such asgevent - Installs
bashallowing interaction with the container - Just like the main
pythondocker image, it creates useful symlinks that are expected to exist, e.g.python3.4>python,pip2.7>pip, etc.) - Added
testingrepository to Alpine's/etc/apk/repositoriesfile
The code in this repository, unless otherwise noted, is MIT licensed. See the LICENSE file in this repository.