It has become a confusing title, but it looks like this
Development PC: Mac Mojave RaspBerry Pi4 memory 4GB SD card 16GB
https://ubuntu.com/download/raspberry-pi I downloaded the 64-bit version from and wrote it using balena Etchar.
Enter Ubuntu with ssh or something
sudo apt-get install docker-ce
You can install it with.
sudo usermod -aG docker ubuntu
You can docker without using sudo.
You can write a python script on the development PC and then copy it to dockerImage with Dockerfile, but it was difficult to understand, so once you make a base with Dockerfile, enter a container and create an image from that container.
Dockerfile
[Building a Docker environment for TensorFlow with Raspberry Pi](https://qiita.com/kohbis/items/53c27ce6c62a7039aaa2#raspberrypi-%E3%81%AB-docker-%E3%82%92%E3%81%88%E3 % 81% 84% E3% 82% 84) I referred to this article, almost above. I wanted to put rpi.gpio, but I didn't know how to put it, so I just wrote it.
FROM resin/rpi-raspbian:stretch
RUN echo "deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware" > /etc/apt/sources.list
RUN apt-get update -y
RUN apt-get install -y --no-install-recommends \
vim git less wget \
build-essential \
libatlas-base-dev \
python3-pip python3-dev python3-setuptools\
python3-scipy python3-h5py \
libraspberrypi-bin \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install --upgrade pip setuptools
RUN pip3 install rpi.gpio
Then build
docker build -t rpi/rpi:0.1 .
Make sure you can do it with docker images! It should be done.
Start the container from the image you created earlier.
docker run --name rpi_test -ti --privileged rpi/rpi:0.1 /bin/bash
Then, it will be inside the container, so install what you want. Because it is a nano school
sudo apt-get update
sudo apt-get install nano
Go to home and make a script. I think it's better to set a working directory around here ...
cd home
nano test.py
It is a program that puts an LED on GPIO17 and makes an appropriate L flickering.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
while True:
GPIO.output(11, True)
time.sleep(2)
GPIO.output(11, False)
time.sleep(2)
After saving the script
exit
Please log out with
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e700d8490be8 rpi/rpi:0.1 "/usr/bin/entry.sh /…" 11 minutes ago Exited (0) 6 seconds ago rpi_test
The container is stopped. To make an image from this container
docker commit rpi_test rpi/rpi:0.2
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rpi/rpi 0.2 50f7f2a406e7 2 minutes ago 622MB
You now have an image with the script saved.
sudo docker run --privileged -it -d --name rpi -w /home rpi/rpi:0.2 python3 test.py
The container moves in the background and keeps fluttering! If you want to stop it, stop with docker stop rpi
I want to get sensor data soon
Recommended Posts