Building docker image on raspberry pi 3b with python 3 and numpy scipy pillow

Building a Docker image on a Raspberry Pi 3B with Python 3, NumPy, SciPy, and Pillow can be achieved in different ways. In this article, we will explore three different options to solve this problem.

Option 1: Using a Dockerfile

The first option is to use a Dockerfile to define the steps required to build the image. Here is an example of a Dockerfile that can be used:


FROM resin/rpi-raspbian:stretch

RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip3 install numpy scipy pillow

CMD ["python3"]

To build the Docker image, save the above Dockerfile in a directory and run the following command:


docker build -t myimage .

This will create a Docker image named “myimage” with Python 3, NumPy, SciPy, and Pillow installed.

Option 2: Using a Docker Compose file

The second option is to use a Docker Compose file to define the services required for the image. Here is an example of a Docker Compose file that can be used:


version: '3'
services:
  myservice:
    build:
      context: .
      dockerfile: Dockerfile
    image: myimage

To build the Docker image, save the above Docker Compose file in a directory along with the Dockerfile from option 1, and run the following command:


docker-compose build

This will create a Docker image named “myimage” with Python 3, NumPy, SciPy, and Pillow installed.

Option 3: Using a pre-built image

The third option is to use a pre-built Docker image that already has Python 3, NumPy, SciPy, and Pillow installed. This option is the easiest and quickest way to get started. Here is an example of pulling and running a pre-built image:


docker run -it resin/rpi-raspbian:stretch python3

This will pull the pre-built image and start a Python 3 shell where you can import and use NumPy, SciPy, and Pillow.

After exploring these three options, it is clear that the best option depends on the specific requirements of your project. If you need more control over the build process, using a Dockerfile or Docker Compose file is recommended. However, if you are looking for a quick and easy solution, using a pre-built image is the way to go.

Rate this post

4 Responses

    1. I couldnt disagree more. Option 1 is the real game changer here. Docker Compose adds unnecessary complexity and bloat to the stack. Keep it simple and stick to the basics. #LessIsMore

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents