My personal base container for Docker, now with Python!
1.3K
This is my personal base container for Docker, now with Python! Maybe you'll find it helpful too...
The container will probably not be used directly, but rather as a for building
other (Docker) containers on. To do that, specify this as your base image (in
your Dockerfile):
FROM minchinweb/python
# ... and the rest
This packages Python 3.9.
You also probably want to set the UID and GID (User ID number and Group ID
number). This can be done through the environmental variables PUID and GUID
(either the -e option at the command line, or the environment key in your
docker-compose.yaml file).
There is also a folders at /app, /config, /defaults that are owned by the
user. The idea is to have your application use this /config volume for all
its persist-able data, and do this by mounting this as a volume outside of your
container (either the -v option at the command line, or the volumes key in
your docker-compose.yaml file). /app is a logical location for the Python
program you are trying to run.
or, What Problems is This Trying to Solve?
After solving the issues with user permissions and PID 1 with my base container, I wanted to keep those solutions in place for my Python Docker images.
The first thing I tried was to install Python 3.7 using apt. While there is a
python3.7 package that will happily install, there is no corresponding apt
package for
pip
(which is needed to install other Python libraries).
Next I tried to compile Python from source myself. This seemed to work, but it took over an hour. This didn't seem to the most desirable solution.
Finally, I realized I could "borrow" a pre-compiled version of Python from the official image via a "multi-stage build", using the official image as my "build stage". This seems to work, the build time is much better, although a few extra tweaks were needed.
pip doesn't cache downloaded packagesThis builds on my base image.
This also wouldn't work without the official Python image.
apt packages may be needed to support building C extensions with
pip or to allow pre-compiled wheels to work.Content type
Image
Digest
Size
71.6 MB
Last updated
over 5 years ago
docker pull minchinweb/python