Linux, 工作, 生活, 家人

ARM, Gentoo

Gentoo ARM64 Docker Image

There is a long time no article about gentoo on my blog.

Today, I have a whim to do a gentoo ARM64 docker image, so, we have this article.

Please understand that ARM64 Gentoo is experimental, and might be different after a while.

First, we can start from stage3 file, it would be easy to create it. if you don’t know what is stage3 file, I think you should leave this page and learn gentoo from scratch.
it can download arm64 stage3 file from here
https://gentoo.osuosl.org/experimental/arm64/
and extract it to a new directory.

if cannot download file from URL address above, please visit URL above to fetch latest stage3 files.

wget https://gentoo.osuosl.org/experimental/arm64/stage3-arm64-20190613.tar.bz2
mkdir gentoo 
cd gentoo 
sudo tar xf ../stage3-arm64-20190613.tar.bz2

it can modify something in this directory.

Next step is create first docker image, it will contain all stage3 files.

cd ..
sudo tar -C gentoo -c . | docker import - gentoo

Please create a directory with a file named “dockerfile”, and contain following text.

FROM gentoo
RUN mkdir -p /var/run/sshd
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN echo 'root:root' |chpasswd # echo password | passwd --stdin root
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i '/pam_loginuid.so/c session optional pam_loginuid.so' /etc/pam.d/sshd
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD /usr/sbin/sshd -D 

Now, create a gentoo docker image

docker build -t gentoo_sshd ./

Run a new instance with this gentoo docker image

docker run -d --privileged=true --name gentootest -v /work:/work -p 40001:22 -P gentoo_sshd

Now, it can use ssh to login this system and run it, password is root.

ssh -p 40001 root@localhost

Ref
Build SDK in Docker
Create a base image
https://gentoo.osuosl.org/experimental/arm64/
Thanks gyakovlev in irc channel .

發佈留言