It is fine to use Docker on the Raspberry Pi by itself, but it is not so easy to use Docker on the Raspberry Pi as a mini-server.
impetus
The server, which performs periodic crawls, was running on a desktop PC.
Since we planned to prepare a dedicated server in the future, we used Docker for easy server migration.
The container configuration was as follows: docker-compose was configured with docker-compose, docker-machine was used to create a Hyper-V Docker machine on Windows, and docker-compose was uploaded to that machine.
+-------+ +---------+ +-------------+ +---------------------+
| Nginx | --> | Jenkins | --> | Linux + SSH | --> | Node.js + puppeteer |
+-------+ +---------+ +-------------+ +---------------------+
So, the server migration is done by adding the new server as a Docker machine and
% docker-machine 新しいマシン名 % docker-compose up
It only takes a few minutes.
I was interested in the Raspberry Pi and wanted to touch it, so I decided to use the Raspberry Pi as a mini server and upload docker-compose to it.
procedure
I used the this way (direction close to the speaker or towards the speaker) article as a reference to make Docker work on the Raspberry Pi and turn it into a Docker machine.
Dokcer machines have a "generic" driver that turns an existing PC into a Docker machine, which is used to turn a Raspberry Pi into a Docker machine.
Occurrence of a problem
I thought that switching the Docker machine to Raspberry Pi and doing docker-compose up
would be the end of it, but it didn't work at all.
Docker images are incompatible
The CPU of a PC is "x86". On the other hand, Raspberry Pi's CPU is "ARM", so Docker images are not compatible.
The images from the Docker Hub must also be dedicated for "ARM" to work, and as a result, a separate Dockerfile must be created for "ARM".
It is necessary to modify the software for Raspberry Pi and upload it to Raspberry Pi, and then further verify the operation on Raspberry Pi.
The Dockerfile was different, so the configuration was slightly different, and there were many cases where things worked fine on the PC, but an error occurred when we brought it to the Raspberry Pi.
Image creation takes too long.
We still managed to get it to work, but the Docker image creation is done on the Raspberry Pi, so the image creation time was long.
It takes about 30 minutes to create an image of "Linux with xlib + Node.js + Chronium + Japanese font" because we used "puppeteer" for the crawler.
The above is an extreme example, but even at the point of changing from "x86" to "ARM" originally, errors were likely to occur, and on top of that, it took so long to create the image that even a small modification became a chore.
Conclusion.
I think the advantage of Docker is the portability of being able to put what you create in the development environment on the server as is, but if you use the Raspberry Pi as a mini-server, that is completely cut off.
In other words, even if you are developing on a PC, you need to separately redevelop the software exclusively for Raspberry Pi, which makes you feel like you are developing twice.
It was quite a hassle, and when I looked back on what my intention was in using Docker in the first place, I realized that using Raspberry Pi as a mini-server and using Docker there was something different, so I decided against it. I decided not to use Docker there....
There are articles on the street about creating Kubernetes clusters using Raspberry Pi, and I initially fantasized about eventually switching from docker-compose to Kubernetes, but on second thought, I realized that even if I switched to Kubernetes, I would still need a Raspberry Pi to create Docker However, after careful consideration, I came to the conclusion that even with Kubernetes, I would still need a Raspberry Pi to create a Docker image for the Raspberry Pi, so I still wondered what it would be like.
I know those articles are done with stories, but do you actually use them? I would think so.
However, in this case, the problem was where we tried to use the Raspberry Pi as a substitute for a PC. If you want to build something specific for the Raspberry Pi, using Docker is not a problem.
bonus
The contents may be out of date, but I will describe the Dockerfiel for Raspberry Pi that I used.
If anyone is trying to use Docker on a Raspberry Pi and is looking for a Dockerfile, we hope you will find it helpful.
Nginx Dockerfile
FROM tobi312/rpi-nginx COPY copy/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/ COPY copy/etc/nginx/server.key /etc/nginx/ COPY copy/etc/nginx/server.crt /etc/nginx/
Jenkins Dockerfile
FROM djdefi/rpi-jenkins RUN apt-get install -y tzdata RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime RUN echo "Asia/Tokyo" > /etc/timezone
Linux+SSH Dockerfile
FROM resin/rpi-raspbian:latest USER root RUN mkdir /var/run/sshd RUN apt-get update RUN apt-get install -y openssh-server RUN echo 'root:xxxx' | chpasswd RUN sed -i 's/PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config RUN cat /etc/ssh/sshd_config RUN sed -i 's/root:\/bin\/ash/root:\/bin\/bash/' /etc/passwd RUN ssh-keygen -A EXPOSE 22 RUN apt-get install -y tzdata RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime CMD ["/usr/sbin/sshd", "-D"]
Node.js + puppeteer Dockerfile
FROM hypriot/rpi-node RUN apt-get update \ && apt-get install -y \ zip \ unzip \ gconf-service \ libasound2 \ libatk1.0-0 \ libc6 \ libcairo2 \ libcups2 \ libdbus-1-3 \ libexpat1 \ libfontconfig1 \ libgcc1 \ libgconf-2-4 \ libgdk-pixbuf2.0-0 \ libglib2.0-0 \ libgtk-3-0 \ libnspr4 \ libpango-1.0-0 \ libpangocairo-1.0-0 \ libstdc++6 \ libx11-6 \ libx11-xcb1 \ libxcb1 \ libxcomposite1 \ libxcursor1 \ libxdamage1 \ libxext6 \ libxfixes3 \ libxi6 \ libxrandr2 \ libxrender1 \ libxss1 \ libxtst6 \ ca-certificates \ fonts-liberation \ libappindicator1 \ libnss3 \ lsb-release \ xdg-utils \ wget RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime # Japanese font RUN mkdir /noto COPY ./app/font/NotoSansCJKjp-hinted.zip /noto WORKDIR /noto RUN unzip NotoSansCJKjp-hinted.zip && \ mkdir -p /usr/share/fonts/noto && \ cp *.otf /usr/share/fonts/noto && \ /usr/bin/fc-cache -fv WORKDIR / RUN rm -rf /noto WORKDIR /usr/src/app COPY ./app/package.json . COPY ./app/build ./build COPY ./app/views ./views RUN npm install COPY ./app/chromium/chromium-codecs-ffmpeg_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb . RUN sudo dpkg -i chromium-codecs-ffmpeg_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb COPY ./app/chromium/chromium-browser_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb . RUN sudo dpkg -i chromium-browser_65.0.3325.181-0ubuntu0.14.04.1_armhf.deb EXPOSE XXXX CMD [ "npm", "start" ]