/ubuntu-python

A base Docker container for running Python apps with an Ubuntu userland

Primary LanguageDockerfileMIT LicenseMIT

ubuntu-python

Docker Stars Docker Pulls

A base Docker container for running Python apps with an Ubuntu userland, based on alpine-python

Why

alpine-python makes for awesome small containers, but it's a pain to deal with all the binary wheels related to machine/deep learning stuff like Tensorflow, numpy, etc., so I decided to bite the bullet and take on the extra bloat that comes with an Ubuntu distro.

Status & Roadmap

  • Multi-stage, "stripped" builds (requires some tuning of the onbuild images)
  • Travis CI builds
  • Normalize architecture tags (arm32v7, amd64, etc. to match Docker naming conventions)
  • Python 3.7.0
  • Move to Ubuntu 18.04 base image
  • LTO (experimental) optimizations, inspired by revsys
  • Initial armhf containers
  • Initial x86_64 containers, plain + onbuild
  • Python 3.6.3 (x86_64)
  • Scaffolding for multiarch builds
  • Base userland with required libraries for building Python 3.6

Usage

This image runs the python command on docker run. You can either specify your own command, e.g:

docker run --rm -ti rcarmo/ubuntu-python:3.7-amd64 python hello.py

Or extend this image using your custom Dockerfile, e.g:

FROM rcarmo/ubuntu-python:3.7-onbuild-amd64

# for a flask server
EXPOSE 5000
CMD python manage.py runserver

Dont' forget to build your image:

docker build --rm=true -t rcarmo/app .

You can also access bash inside the container:

docker run --rm -ti rcarmo/ubuntu-python:3.7-amd64 /bin/bash

Another option is to build an extended Dockerfile version (like shown above), and mount your application inside the container:

docker run --rm -v "$(pwd)":/home/app -w /home/app -p 5000:5000 -ti rcarmo/app

Details

  • Builds with optimizations enabled, for a significant performance boost
  • There is no latest tag - this is a feature, not a bug, because I prefer to tag my images with the architecture and build step purpose
  • Uses make altinstall to have Python 3.6 coexist with the built-in Ubuntu Python (which is nearly impossible to eradicate anyway)
  • Just like the main python docker image, it creates useful symlinks that are expected to exist, e.g. python3.6 > python, pip3.6 > pip, etc.)