# embedded system final project ## Docker container on raspberry pi3 ### what is docker? docker is a software platform allow user to package the environment and application as a container and deploy on diffrent docker machine. Similar to a virtual machine it containerize the operating system(Operating system–level virtualization) ### why docker? the most important part is ***Write Once, Run Anywhere*** containerization allow user to avoid the ugly environment issue cause by those complex dependency. And once the application fail. It's very easy to restart. Greatly imporve the convieniency of managing the application. ### installation 1. goto https://blog.hypriot.com/post/releasing-HypriotOS-1-11/ 2. follow the step. or 1. goto the official github site https://github.com/hypriot/image-builder-rpi/releases 2. download the version you wish. 3. unzip 4. using dd to burn the image file to sdCard ***note*** > having trouble using the latest version. Causing kernel panic with no reason. > Using HypriotOS v1.12.2 in this project Now the docker is ready. This image also come with ssh enable. ### testing ![](https://i.imgur.com/et7aVZR.png) docker is runing. ### application a python script that call the spotify api to obtain the song that user currently playing. (source code from [[6]](https://github.com/imdadahad/spotify-get-current-playing-track)) ### Dockerfile ```dockerfile= FROM python WORKDIR /usr/src/app COPY requirements.txt ./ RUN python -m pip install --no-cache-dir -r requirements.txt COPY ./spotify_api.py ./ CMD [ "python", "./spotify_api.py" ] ``` ### enable qemu support ```bash= docker run --rm --privileged multiarch/qemu-user-static --reset -p yes ``` ### cross platform since we want to build stuff on our host machine. It's faster and easier. But the platform matters in docker, since it's not a virtual machine. However with the help of the mighty QEMU system. We'd be able to build a multi platform container and export it as an image file. ```bash= docker buildx build --platform linux/arm -t spotify_cross . --load ``` ![](https://i.imgur.com/A9LzKLV.png) ### export build/import on target/result host ```bash= docker save spotify_cross > spotify_cross.tar scp ./spotify_cross.api pirate@[target machine ip]:/home/pirate/docker/ ``` ![](https://i.imgur.com/gQUmFcc.png) target ```bash= docker load < spotify_cross.tar docker run -it --name spotify --rm --privileged spotify_cross bash ./spotify_api.py ``` ![](https://i.imgur.com/UdJEKAQ.png) ## referrence https://philipzheng.gitbook.io/docker_practice/image/save_load https://blog.minirplus.com/16696/ https://www.instructables.com/Uniform-Development-by-Docker-QEMU/ https://peihsinsu.gitbooks.io/docker-note-book/content/run_pi_over_qemu_on_x86.html https://docs.docker.com/desktop/multi-arch/ https://github.com/imdadahad/spotify-get-current-playing-track [6] https://blog.csdn.net/qq_38340601/article/details/115574281 https://www.stereolabs.com/docs/docker/building-arm-container-on-x86/