43 lines
1.1 KiB
Markdown
43 lines
1.1 KiB
Markdown
# Minimal Base Python Container Image
|
|
|
|
The *pythonctnr* image contains ONLY the Python runtime, and nothing else. It
|
|
is suitable for deploying applications written in pure Python, without any
|
|
external library dependencies. No shell or other OS utilities are included.
|
|
Just `/usr/bin/python3` and the libraries it needs to run.
|
|
|
|
|
|
## Building
|
|
|
|
The contents of the container image are built with [buildroot][0].
|
|
|
|
```sh
|
|
make -C ~/src/buildroot O=${PWD}/_build pythonctnr_defconfig
|
|
make -C _build
|
|
```
|
|
|
|
This will produce a `rootfs.tar` tarball in `_build/images`, which is then
|
|
converted to a container image using `buildah`.
|
|
|
|
```sh
|
|
ctnr=$(buildah from scratch)
|
|
buildah add ${ctnr} _build/images/rootfs.tar /
|
|
buildah commit ${ctnr} pythonctnr:latest
|
|
```
|
|
|
|
[0]: https://buildroot.org/
|
|
|
|
|
|
## Usage
|
|
|
|
The container image can be used like any other image, e.g. in a `Dockerfile`.
|
|
*pip* is included, to allow installing Python distribution packages.
|
|
|
|
```Dockerfile
|
|
FROM pythonctnr
|
|
|
|
RUN ["/usr/bin/python3", "-m", "pip", "install", "mypkg"]
|
|
```
|
|
|
|
**NOTE**: Because there is no shell, the default string form of the `RUN`
|
|
instruction does not work. You must use the *exec* form.
|