Dockerising Python Scripts (Python Script Container)

The following is a generic Docker image for running Python scripts. I personally use this to host long running Python scripts such as MQTT clients and virtualised hardware such as the RF MQTT Gateway and Audio Buzzer.

It doesn’t make sense for me to upload it to Dockerhub because you will have to specify the dependencies of your Python script to be installed during docker build.

If there is a way to make this easier, please let me know.

FROM arm32v7/python:3.6.4-slim-jessie

RUN apt-get update && apt-get install -y python-dev python3-dev build-essential pkg-config libfreetype6-dev libpng12-dev

# Specify any dependencies required by your script in here
#RUN pip3 install RPi.GPIO paho-mqtt

RUN mkdir app


CMD ["python", "./"]

The docker-compose.yaml file is where your Python script is loaded into the container. This means you can use the same image to run multiple python scripts (as long as they have the same dependencies)

version: "3"
    build: .
    restart: unless-stopped
      - ./

The reason I (have to) create these custom containers is because the offical image sources often do not supply compiled images for arm platforms. Since I run Docker exclusively on Raspbrery Pi, I often find myself compiling (and fixing in the process) images from scratch…

I hope this helps you. As always I welcome suggestions for improvement, the fact that dependencies have to be specified and a new image compiled every time seems weird.