This article is the 7th day of "Docker Advent Calendar 2020". I filled it because it was open. The day before, @ c3drive's Building a container environment on AWS
-Nerves is -Elixir's IoT is now and young cool awesome guy: rocket: -You can enjoy IoT development with a programming language called Elixir. -Nerves requires various environment settings ――It's not so once you get used to it, but there are various traps to do for the first time. --So, @takasehideki-sensei said IoT # 4.1.2 with Elixir: [How to use] Docker (and VS Code) only! Improve Nerves development environment has been released. ――I want an acquaintance to try it right away! -Can't this container be run on Azure Container Instances at a group meeting called NervesJP? I heard a story like that, so I thought it was a good story.
Dockerfile
# docker-elixir 1.11.2
# https://hub.docker.com/_/elixir
FROM elixir:1.11.2
ENV DEBCONF_NOWARNINGS yes
# Install libraries for Nerves development
RUN apt-get update && \
apt-get install -y build-essential automake autoconf git squashfs-tools ssh-askpass pkg-config curl openssh-server && \
rm -rf /var/lib/apt/lists/*
RUN mkdir /var/run/sshd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
COPY ./config_files/id_rsa.pub /root/.ssh/authorized_keys
EXPOSE 22
# [Optional] Uncomment this section to install libraries for customizing Nerves System
#RUN apt-get update && \
# apt-get install -y libssl-dev libncurses5-dev bc m4 unzip cmake python && \
# rm -rf /var/lib/apt/lists/*
# Install fwup (https://github.com/fhunleth/fwup)
ENV FWUP_VERSION="1.8.2"
RUN wget https://github.com/fhunleth/fwup/releases/download/v${FWUP_VERSION}/fwup_${FWUP_VERSION}_amd64.deb && \
apt-get install -y ./fwup_${FWUP_VERSION}_amd64.deb && \
rm ./fwup_${FWUP_VERSION}_amd64.deb && \
rm -rf /var/lib/apt/lists/*
# Install hex and rebar
RUN mix local.hex --force
RUN mix local.rebar --force
# Install Mix environment for Nerves
RUN mix archive.install hex nerves_bootstrap 1.10.0 --force
CMD ["/usr/sbin/sshd", "-D"]
-Enabled ssh
connection based on https://github.com/NervesJP/docker-nerves/blob/v0.2/Dockerfile
--For the ssh
connection, I referred to @ kuboshu83's [Introduction to Docker] Setting memo for accessing the container with ssh.
ssh
connection possible.
--I have config_files/id_rsa.pub
--For id_rsa.pub
, I used the one already created in ~/.ssh/
.
--If you don't have such a file, just google with ssh-keygen
and you'll surely find the answer.$ mkdir config_files
$ cp ~/.ssh/id_rsa.pub config_files/
$ docker build -t docker-nerves .
――After creating the image, the rest of the procedure is as follows
―― 1. Register the image in Azure Container Registry
--2. Set Azure Container Instances to use the custom image.
―― 3. Connect with ssh
and develop Nerves application
――Hereafter, we will take a closer look.
--Quick Start: Create an Azure Container Registry Using the Azure Portal (https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-get-started-portal)
-: Point_up :: point_up_tone :: point_up_tone2 :: point_up_tone3 :: point_up_tone4 :: point_up_tone5: You should do as it is written here.
――I didn't use any Azure CLI to push images
--There is a page called "Quick Start" on the console of Azure Container Registry, so you can refer to it.
--First, go to the page called "Access Keys" and enable the admin user
--Use the username and password written there with docker login
$ docker login xxx.azurecr.io
$ docker tag docker-nerves xxx.azurecr.io/docker-nerves
$ docker push xxx.azurecr.io/docker-nerves
--xxx is the name (value) you decided when you created Azure Container Registry.
-Quick Start: Deploy a container instance in Azure using the Azure portal
--The network should be public
and port 22
should be open.
--That's all you need to set, and then Next`` Next
--The container will start up after a while, so remember the assigned IP address.
--Hereafter, assume that it is 20.43.93.225
--This container was deleted after writing the article
ssh
and develop Nerves app$ ssh [email protected]
: point_up :: point_up_tone :: point_up_tone2 :: point_up_tone3 :: point_up_tone4 :: point_up_tone5: Enter the container
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096
$ cd
$ mix nerves.new hello_nerves
$ cd hello_nerves
$ export MIX_TARGET=rpi4
$ mix deps.get
$ mix firmware
So, the firmware is safely in the container
You can create /root/hello_nerves/_build/rpi4_dev/nerves/images/hello_nerves.fw
: fire :: fire :: fire:
For other than Raspberry Pi 4, select a value from Targets.
$ scp [email protected]:/root/hello_nerves/_build/rpi4_dev/nerves/images/hello_nerves.fw .
--Bring firmware from a container in the cloud --Insert the microSD card into the development machine
$ fwup hello_nerves.fw
--Oh, I didn't explain how to install fwup. .. ..
――There
--Install fwup
:gift::gift::gift:
--Nothing was done in this article where you mentioned that you wanted to mix upload
(that is, ssh) from a cloud container to a Raspberry Pi.
--When you execute the mix
command
warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)
There was a little warning.
--You can make various things: rocket :: rocket :: rocket: --Introducing a simple example ――This is miso in the foreground -Nerves alarm created with Raspberry Pi 4 + Grove Base HAT for Raspberry Pi + Grove Buzzer + Grove Button
.ex
in the container?-You can go with Visual Studio Code -Please refer to Remote Development using SSH ――You can proceed with development as if you were editing a local file like this.
Wrapping Up :christmas_tree::santa::santa_tone1::santa_tone2::santa_tone3::santa_tone4::santa_tone5::christmas_tree:
--There may be a smarter way to deal with @ takasehideki's Dockerfile
as it is without rewriting.
--I want to mix upload
(that is, ssh) from a cloud container to a Raspberry Pi! ?? I haven't stepped into a story like that
Tomorrow is @ kosuketakei's A programmer from a liberal arts background who has no work experience tried using Docker. Please continue to enjoy.