vszal / distroless-python

Using distroless.dev's apko to generate distroless images for building and running python containers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deprecated

Chainguard.dev now has it's own python image

distroless-python

TLDR: This repo contains sample apko.yaml files for generating Chainguard's distroless container base images for building and running containerized python apps.

Overview

example/Dockerfile shows sample multi-stage build (separate "builder" and "runner" base images). These two base images must be built and hosted in your repo. They are generated by apko. The builder image is generated using apko-python-builder.yaml and the run image is generated using apko-python.yaml. Note, this example is tailored around a python flask application with gunicorn such as this one; you may need to adjust base image packages in the apko-python.yaml file for your use case.

Get the apko development image

To create these distroless base images you will need the apko tool. Follow the docs to pull the apko docker image.

Creating the builder image

  1. Use the distroless.dev/apko image to build and output the python-builder.tar file:
docker run -v $PWD:/work distroless.dev/apko build apko-python-builder.yaml \ 
YOUR-REPO/python-distroless-builder:latest python-builder.tar

Be sure to replace YOUR-REPO.

  1. Load the builder image from the tar file:

docker image load --input python-builder.tar

  1. Replace YOUR-REPO and push the image:

docker push YOUR-REPO/python-distroless-builder:latest

Creating the run image

  1. Use the distroless.dev/apkoimage to build and output the python.tar file:
docker run -v $PWD:/work distroless.dev/apko build apko-python.yaml \
YOUR-REPO/python-distroless:latest python.tar

Be sure to replace YOUR-REPO.

  1. Load the builder image from the tar file:

docker image load --input python.tar

  1. Replace YOUR-REPO and push the image:

docker push YOUR-REPO/python-distroless:latest

Use the produced base images

See the example/Dockerfile for example usage.

Feedback

Please send me any feedback and pull requests.

About

Using distroless.dev's apko to generate distroless images for building and running python containers

License:MIT License


Languages

Language:Dockerfile 100.0%