<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>docker &#8211; richliu&#039;s blog</title>
	<atom:link href="https://richliu.com/tag/docker/feed/" rel="self" type="application/rss+xml" />
	<link>https://richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Thu, 25 Mar 2021 03:15:43 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>CentOS8 ARM64/AARCH64 Install Docker</title>
		<link>https://richliu.com/2020/05/18/4273/centos8-arm64-aarch64-install-docker/</link>
					<comments>https://richliu.com/2020/05/18/4273/centos8-arm64-aarch64-install-docker/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Mon, 18 May 2020 15:11:17 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[centos8]]></category>
		<category><![CDATA[docker]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4273</guid>

					<description><![CDATA[<p>It&#8217;s not complex to install docker on ARM64 platf [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2020/05/18/4273/centos8-arm64-aarch64-install-docker/">CentOS8 ARM64/AARCH64 Install Docker</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>It&#8217;s not complex to install docker on ARM64 platform and make it work, but it needs a trick</p>



<span id="more-4273"></span>



<h2 class="wp-block-heading">Remove Packages </h2>



<p>$  sudo yum remove docker-ce docker-ce-cli containerd.io </p>



<h2 class="wp-block-heading">Install Containterd First</h2>



<p>This is most important step, without this, docker&#8217;s install script will fail. </p>



<p>$ sudo dnf install <a href="https://download.docker.com/linux/centos/7/aarch64/stable/Packages/containerd.io-1.2.6-3.3.el7.aarch64.rpm" target="_blank" rel="noopener">https://download.docker.com/linux/centos/7/aarch64/stable/Packages/containerd.io-1.2.6-3.3.el7.aarch64.rpm</a></p>



<h2 class="wp-block-heading">Docker Script</h2>



<p>Get docker script and run it <br />$ curl -fsSL https://get.docker.com -o get-docker.sh <br />$ sudo sh get-docker.sh <br />Add your current username to docker group if not run on root account. <br />$ sudo usermod -aG docker your-user </p>



<h2 class="wp-block-heading">Restart Docker And Enable Firewall </h2>



<p>$  sudo systemctl start docker <br />$  firewall-cmd &#8211;zone=public &#8211;add-masquerade &#8211;permanent <br />$  firewall-cmd &#8211;reload </p>



<p>ref. <br />[1]  https://linuxconfig.org/how-to-install-docker-in-rhel-8 <br />[2]  https://docs.docker.com/engine/install/centos/ <br />[3]  https://serverfault.com/questions/987686/no-network-connectivity-to-from-docker-ce-container-on-centos-8 </p>
<p>The post <a rel="nofollow" href="https://richliu.com/2020/05/18/4273/centos8-arm64-aarch64-install-docker/">CentOS8 ARM64/AARCH64 Install Docker</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2020/05/18/4273/centos8-arm64-aarch64-install-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>QEMU Network Problem When Run With Docker</title>
		<link>https://richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/</link>
					<comments>https://richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Wed, 16 Oct 2019 06:44:21 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[qemu]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4190</guid>

					<description><![CDATA[<p>如果 Docker 和 QEMU 同時執行時，QEMU 內部透過 tap interface bridge 到 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/">QEMU Network Problem When Run With Docker</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>如果 Docker 和 QEMU 同時執行時，QEMU 內部透過 tap interface bridge 到 host network 的網路會出不去<br /><br />這個問題的原因是 Docker 起來之後，會將 iptables 的 packet forward 預設變成 DROP<br /><br />這時可以在 Docker 起來的時候將 bridge interface 加到 iptables 規則內即可，首先編輯 systemd docker service </p>



<span id="more-4190"></span>



<pre class="wp-block-preformatted">EDITOR=vim sudo -E systemctl edit docker</pre>



<p>加上這一段</p>



<pre class="wp-block-preformatted">[Service] 
ExecStartPre=/sbin/iptables -A FORWARD -p all -i br0 -j ACCEPT 
ExecStopPost=/sbin/iptables -D FORWARD -p all -i br0 -j ACCEPT</pre>



<p><br />再重啟你的 Docker 就好了</p>



<pre class="wp-block-preformatted">sudo systemctl stop docker 
sudo systemctl start docker </pre>



<p>要不然就簡單一點，將 FORWARD rule 從預設 DROP 變成 ACCEPT</p>



<pre class="wp-block-preformatted">[Service] 
ExecStartPre=/sbin/iptables -P FORWARD ACCEPT </pre>



<p>ref<br /><a href="https://bbs.archlinux.org/viewtopic.php?id=233727" target="_blank" rel="noreferrer noopener" aria-label="[SOLVED] Docker breaks existing bridge I use for KVM/QEMU (opens in a new tab)">[SOLVED] Docker breaks existing bridge I use for KVM/QEMU</a></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/">QEMU Network Problem When Run With Docker</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Gentoo ARM64 Docker Image</title>
		<link>https://richliu.com/2019/08/02/4049/gentoo-arm64-docker-image/</link>
					<comments>https://richliu.com/2019/08/02/4049/gentoo-arm64-docker-image/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 02 Aug 2019 07:43:30 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[docker]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=4049</guid>

					<description><![CDATA[<p>There is a long time no article about gentoo on my blog [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/08/02/4049/gentoo-arm64-docker-image/">Gentoo ARM64 Docker Image</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There is a long time no article about gentoo on my blog. <br /><br />Today, I have a whim to do a gentoo ARM64 docker image, so, we have this article. </p>



<div class="wp-block-image"><figure class="alignright is-resized"><img decoding="async" src="https://richliu.com/wp-content/uploads/2019/08/擷取-1024x478.png" alt="" class="wp-image-4050" width="309" height="143" srcset="https://richliu.com/wp-content/uploads/2019/08/擷取-1024x478.png 1024w, https://richliu.com/wp-content/uploads/2019/08/擷取-300x140.png 300w, https://richliu.com/wp-content/uploads/2019/08/擷取-768x359.png 768w, https://richliu.com/wp-content/uploads/2019/08/擷取.png 1441w" sizes="(max-width: 309px) 100vw, 309px" /></figure></div>



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



<span id="more-4049"></span>



<p>First, we can start from stage3 file, it would be easy to create it. if you don&#8217;t know what is stage3 file, I think you should leave this page and learn gentoo from scratch. <br />it can download arm64 stage3 file from here<br /> <a href="https://gentoo.osuosl.org/experimental/arm64/" target="_blank" rel="noopener">https://gentoo.osuosl.org/experimental/arm64/</a> <br />and extract it to a new directory. <br /><br />if cannot download file from URL address above, please visit URL above to fetch latest stage3 files.</p>



<pre class="wp-block-preformatted">wget https://gentoo.osuosl.org/experimental/arm64/stage3-arm64-20190613.tar.bz2
mkdir gentoo 
cd gentoo 
sudo tar xf ../stage3-arm64-20190613.tar.bz2</pre>



<p>it can modify something in this directory. </p>



<p>Next step is create first docker image, it will contain all stage3 files. </p>



<pre class="wp-block-preformatted">cd ..
sudo tar -C gentoo -c . | docker import - gentoo</pre>



<p>Please create a directory with a file named &#8220;dockerfile&#8221;, and contain following text.</p>



<pre class="wp-block-preformatted">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 </pre>



<p>Now, create a gentoo docker image </p>



<pre class="wp-block-preformatted">docker build -t gentoo_sshd ./</pre>



<p>Run a new instance with this gentoo docker image </p>



<pre class="wp-block-preformatted">docker run -d --privileged=true --name gentootest -v /work:/work -p 40001:22 -P gentoo_sshd</pre>



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



<pre class="wp-block-code"><code>ssh -p 40001 root@localhost</code></pre>



<p>Ref<br /><a href="https://richliu.com/2017/12/24/2199/build-sdk-in-docker">Build SDK in Docker</a><br /><a href="https://docs.docker.com/develop/develop-images/baseimages/" target="_blank" rel="noopener">Create a base image</a><br /><a href="https://gentoo.osuosl.org/experimental/arm64/" target="_blank" rel="noopener">https://gentoo.osuosl.org/experimental/arm64/</a> <br />Thanks gyakovlev in irc channel . </p>
<p>The post <a rel="nofollow" href="https://richliu.com/2019/08/02/4049/gentoo-arm64-docker-image/">Gentoo ARM64 Docker Image</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2019/08/02/4049/gentoo-arm64-docker-image/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Build SDK in Docker</title>
		<link>https://richliu.com/2017/12/24/2199/build-sdk-in-docker/</link>
					<comments>https://richliu.com/2017/12/24/2199/build-sdk-in-docker/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Sun, 24 Dec 2017 05:24:14 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[sdk]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=2199</guid>

					<description><![CDATA[<p>這一篇是我在弄編某家 IC 設計公司的 SDK 的弄的 Docker document 時寫的文件, 懶得轉成 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2017/12/24/2199/build-sdk-in-docker/">Build SDK in Docker</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>這一篇是我在弄編某家 IC 設計公司的 SDK 的弄的 Docker document 時寫的文件, 懶得轉成中文了, 所以大家就將就看一下吧<br /><br />最早是因為 Host OS 已經升級, 但是編 SDK 一直出問題, 所以只好弄一個環境編譯 SDK<br /> Ubuntu 16.04 應該是目前最穩定的版本, 所以以下的文件也都是基於 Ubuntu 16.04 寫的 最後的 Docker file 可以安裝和編譯該家公司目前大多數的 SDK, 或許也適合其他家公司使用.<br /> 給各位參考一下   </p>



<span id="more-2199"></span>



<h2 class="wp-block-heading">Why Need Docker</h2>



<p>Some people run VM to compile SDK, but VM has one problem, every VM needs one disk, whatever virtual or physical. if have a lot of SDK versions, VM will be too heavy to run different version of SDK.<br />Docker is a technical to provide container, it can isolate to run another OS with the same kernel.<br />Docker just like chroot, can switch to another directory and run system inside the directory.<br />So, if have problem on compile SDK, and wants to use another OS, use Docker means we don&#8217;t need to create new VM or find new PC to install new OS. It can save time on install OS.</p>



<h2 class="wp-block-heading">Install Docker</h2>



<p>If you are using VMWare Workstation as virtual machine runs on Windows<br /> suggest to run Ubuntu 17.10 in VM. kernel is more stable than Ubuntu 17.04.<br /> This guide is for Ubuntu, but I think it can easy to do the same thing on<br /> other Linux distributions.<br /> it&#8217;s easy to install Docker with following command<br /><br /></p>



<pre class="wp-block-preformatted"> $ sudo apt install docker.io</pre>



<p>edit /etc/group and add your account to group docker, then, re-login. replace username with your account name<br /></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>docker:x:132:[username]<br /></p></blockquote>



<h2 class="wp-block-heading"> Create Docker Image </h2>



<p>Before use Docker, it needs to create new image with sshd.<br />
After create Docker image, we can use this image to run Docker containers.<br />
First step:<br />
create a folder, ex: in /work/docker/ubuntu</p>



<pre class="wp-block-preformatted">$ mkdir -p /work/docker/ubuntu</pre>



<p>Second step:<br />create a file name &#8220;dockerfile&#8221;, this file will download ubuntu 16.04 official Docker image, and install/run sshd.<br />this dockerfile will create only one account &#8220;root&#8221;.<br />Following is contain of file name &#8220;dockerfile&#8221;, please save it as file &#8220;dockerfile&#8221;</p>



<pre class="wp-block-preformatted">FROM ubuntu:16.04
RUN apt-get update &amp;&amp; apt-get install -y openssh-server
RUN mkdir /var/run/sshd
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" &gt;&gt; /etc/profile
EXPOSE 22
CMD bash /root/service.sh ; /usr/sbin/sshd -D</pre>



<p>Third Step:<br />Build Docker image, ubuntu_sshd is image name, you can replace it with what you like</p>



<pre class="wp-block-preformatted">$ cd /work/docker/ubuntu
$ docker build -t ubuntu_sshd ./</pre>



<p>Next step, check the image list with Docker images command</p>



<pre class="wp-block-preformatted">$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu_sshd latest a35b72393f98 7 days ago 216 MB
centos7_sshd latest 5863726c0ae2 8 days ago 282 MB
centos centos6 5dedbd63518e 8 weeks ago 194 MB</pre>



<p>if you don&#8217;t want this image, use docker rmi to remove it.</p>



<pre class="wp-block-preformatted">$ docker rmi 5dedbd63518e
Untagged: centos:centos6
Untagged: centos@sha256:27129d34f09970d0a348e789b7dba7d1bf39bc346eb5931a9c4dd3be658dfa75
Deleted: sha256:5dedbd63518eeb45b6c9740d9ea6dee99a4a4c3d0202eac25ebc5fd43809f0a0
Deleted: sha256:80716a2ba414a02bb63de844acff6578a25b8583b01cf0a4c2653da50a31e305</pre>



<p>At least, it might have another requirement about to use other OS like centos.<br />
Here is centos dockerfile, you can change number 7 to get other centos version</p>



<pre class="wp-block-preformatted">FROM centos:centos7
RUN yum install -y which openssh-clients openssh-server
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 '/pam_loginuid.so/c session optional pam_loginuid.so' /etc/pam.d/sshd
EXPOSE 22
CMD bash /root/service.sh ; /usr/sbin/sshd -D</pre>



<h2 class="wp-block-heading">Run Docker Container</h2>



<p>Run docker container is very easy, following command is to run docker container,<br />-v /work:/work means it can share host /work with /work inside docker.<br />-P means will create a port mapping to port 22 inside docker<br />&#8211;privileged=true can allow mount loop back devices.</p>



<pre class="wp-block-preformatted">$ docker run --privileged=true -d --name sdk620 -v /work:/work -P ubuntu_sshd</pre>



<p>Aftet this command, it will see docker image is running</p>



<pre class="wp-block-preformatted">$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
693fdc5ff6c4 ubuntu_sshd "/bin/sh -c '/usr/..." 1 hours ago Up 1 hours
0.0.0.0:32768-&gt;22/tcp sdk620</pre>



<p>it can also use outside Docker image resource, like rastasheep.<br /> rastasheep provides a ubuntu sshd environment, so, that means it doesn&#8217;t need to create Docker image ourselves,  if just need a sshd environment.<br /> Visit this web for more information<br /> https://hub.docker.com/r/rastasheep/ubuntu-sshd/<br /><br /> run following command to create a docker container from rastasheep, it will download some files from internet.</p>



<pre class="wp-block-preformatted">$ docker run -d --name test -v /work:/work -P rastasheep/ubuntu-sshd:16.04
16.04: Pulling from rastasheep/ubuntu-sshd
ae79f2514705: Already exists
[ignore download message]
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
dfbfed255ff4 rastasheep/ubuntu-sshd:16.04 "/usr/sbin/sshd -D" 16 seconds ago
Up 14 seconds 0.0.0.0:32771-&gt;22/tcp test</pre>



<p>sometimes, VM crash or host reboot, docker containers are gone,<br />
it can use docker ps -a to find it, ex:</p>



<pre class="wp-block-preformatted">$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
693fdc5ff6c4 ubuntu_sshd "/bin/sh -c '/usr/..." 19 hours ago
Exited (137) 11 hours ago sdk620
now we can get docker id and run it again
$ docker start 693fdc5ff6c4
Check current status, it can see docker containers running again,
but mapping port maybe different
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
7000c5d55029 ubuntu_sshd "/bin/sh -c '/usr/..." 11 hours ago Up 11
hours 0.0.0.0:32768-&gt;22/tcp sdk510-2
693fdc5ff6c4 ubuntu_sshd "/bin/sh -c '/usr/..." 19 hours ago Up 11
seconds 0.0.0.0:32769-&gt;22/tcp sdk620</pre>



<p>Everytime restart docker image, the binding port will be re-assigned,<br /> if needs to fix the binding port, it can use -p parameter, for example, following command will assign localhost port 40001 to port 22. please notice, only can assign it before create it.</p>



<pre class="wp-block-preformatted">$ docker run -d --privileged=true --name sdk620-2 -v /work:/work -p 40001:22 -P ubuntu_sshd</pre>



<h2 class="wp-block-heading">SSH into Docker Container</h2>



<p>Now, it has running docker container, next step is to use ssh to login docker container.</p>



<p>if doesn&#8217;t have ssh key, please generate one. default value is good for docker. Don&#8217;t need higher security in this circumstance</p>



<pre class="wp-block-preformatted">$ ssh-keygen</pre>



<p>in previous docker ps information, we can know sdk620&#8217;s open port is 32769.</p>



<pre class="wp-block-preformatted">$ docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
693fdc5ff6c4 ubuntu_sshd "/bin/sh -c '/usr/..." 19 hours ago Up 11
seconds 0.0.0.0:32769-&gt;22/tcp sdk620

$ ssh-copy-id -p 32769 root@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/username/.ssh/id_rsa.pub"
Number of key(s) added: 1
</pre>



<p>Now try logging into the machine, with: &#8220;ssh -p &#8216;32769&#8217; &#8216;root@localhost'&#8221; and check to make sure that only the key(s) you wanted were added.<br /></p>



<p>Now, it can ssh to Docker container</p>



<pre class="wp-block-preformatted">$ ssh -p 32769 root@localhost
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.13.0-16-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Last login: Wed Nov 8 08:14:13 2017 from 172.17.0.1
root@693fdc5ff6c4:~#</pre>



<p>Please understand, this Docker image only contain basic function, even doesn&#8217;t have some basic commands like sudo or other commands. Here is some example commands to install basic packages.</p>



<pre class="wp-block-preformatted">echo "export LC_ALL=C" | tee ~/.bashrc
apt update
apt -y upgrade
apt -y install vim tmux lftp net-tools ethtool bc sudo wget</pre>



<p>If you prepare to install SDK, it needs to install build environment<br /><br />First, modify /etc/apt/source.list , replace &#8220;# deb-src&#8221; with &#8220;deb-src&#8221; remove # and include all source packages.</p>



<pre class="wp-block-preformatted">$ apt update</pre>



<p>Install
build kernel packages</p>



<pre class="wp-block-preformatted">$ apt-get build-dep linux-image-lowlatency-lts-xenial</pre>



<p>Install
build other packages&#8217;s packages</p>



<pre class="wp-block-preformatted">$ apt -y install vim tmux lftp net-tools ethtool bc sudo wget
$ apt-get -y build-dep linux-image-lowlatency-lts-xenial
$ apt install -y docbook-utils libncurses5-dev help2man texinfo m4 flex
$ apt install -y bison autoconf libltdl-dev libltdl7 zlib1g-dev uuid-dev
$ apt install -y pkg-config alien libglib2.0-dev pigz liblz4-tool
$ apt install -y libssl-dev pkg-config aptitude m4 flex bison texinfo
$ aptitude install -y liblz4-tool pandoc texlive-xetex device-tree-compiler</pre>



<p>Next
Step, it can use alien to install SDK rpm packages</p>



<pre class="wp-block-preformatted">$ alien -i --script *.rpm</pre>



<h2 class="wp-block-heading">Create new Docker Image for build SDK</h2>



<p>combind all information above,we can create a new image which can provide an Docker image to compile SDK<br />First, create a ubuntu 16.04 dockerfile like following</p>



<pre class="wp-block-preformatted">FROM ubuntu:16.04
RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list
# following line is local proxy example configuration file.
# RUN echo "Acquire::http::Proxy \"http://192.168.1.254:3142\";" &gt;&gt; /etc/apt/apt.conf
RUN apt-get update &amp;&amp; apt-get install -y openssh-server apt-utils
RUN mkdir -p /var/run/sshd
RUN apt -y install vim tmux lftp net-tools ethtool bc sudo wget
RUN apt-get -y build-dep linux-image-lowlatency-lts-xenial
RUN apt install -y docbook-utils libncurses5-dev help2man texinfo m4 flex
RUN apt install -y bison autoconf libltdl-dev libltdl7 zlib1g-dev uuid-dev
RUN apt install -y pkg-config alien libglib2.0-dev pigz liblz4-tool
RUN apt install -y libssl-dev pkg-config aptitude m4 flex bison texinfo
RUN apt install language-pack-en
RUN aptitude install -y liblz4-tool pandoc texlive-xetex device-tree-compiler
RUN apt -y upgrade
RUN apt autoclean
#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" &gt;&gt; /etc/profile
EXPOSE 22
CMD bash /root/service.sh ; /usr/sbin/sshd -D</pre>



<p>If used Centos, here has another example</p>



<pre class="wp-block-preformatted">FROM centos:centos7
RUN yum install -y which openssh-clients openssh-server #-y表示交互都输入yes
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 '/pam_loginuid.so/c session optional pam_loginuid.so' /etc/pam.d/sshd
RUN yum install -y bc sudo zlib-devel uuid-devel yum libuuid-devel.i686 uuid-devel.i686
RUN yum install -y vim perl-Env patch ncurses ncurses-devel glibc.i686
RUN yum install -y device-mapper-devel dtc gdisk glib2-devel libfdt
RUN yum install -y libfdt-devel libpcap libpcap-devel openssl openssl-devel
RUN yum install -y pciutils pciutils-devel texinfo-tex pigz libuuid-devel
RUN yum groupinstall -y 'Development Tools'
EXPOSE 22
CMD bash /root/service.sh ; /usr/sbin/sshd -D</pre>



<p>Build a Docker image</p>



<pre class="wp-block-preformatted">$ docker build -t ubuntu1604_sdk ./</pre>



<p>It will take ten minutes or more depend on network speed. After finish build image, it can use following command to check current status.</p>



<pre class="wp-block-preformatted">$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu1604_sdk latest 9f02c2ad68c4 36 minutes ago 2.14 GB</pre>



<p>Then, we can run new Docker container with this image.</p>



<pre class="wp-block-preformatted">$ docker run -d --privileged=true --name sdk620-2 -v /work:/work -p 40001:22 -P ubuntu1604_sdk</pre>



<h2 class="wp-block-heading">Remove a running Docker container</h2>



<p>Ff project closed or don&#8217;t really need Docker container, it can be removed. use docker ps to find which one container we don&#8217;t need.</p>



<pre class="wp-block-preformatted">$ docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
7000c5d55029 ubuntu_sshd "/bin/sh -c '/usr/..." 11 hours ago Up 11
hours 0.0.0.0:32768-&gt;22/tcp sdk510-2
693fdc5ff6c4 ubuntu_sshd "/bin/sh -c '/usr/..." 20 hours ago Up 25
minutes 0.0.0.0:32769-&gt;22/tcp sdk620
51b5fff37d74 centos/centos7 "/bin/sh -c '/usr/..." 37 hours ago Up 2
seconds 0.0.0.0:32770-&gt;22/tcp sdk510</pre>



<p>Sdk510 with centos7 will fail to compile, I don&#8217;t need it.<br />run following command to stop it.</p>



<pre class="wp-block-preformatted">$ docker stop 51b5fff37d74</pre>



<p>run following command to remove it.</p>



<pre class="wp-block-preformatted">$ docker rm 51b5fff37d74</pre>



<p>sdk510 Docker container won&#8217;t occupy disk anymore. but please use it carefully,<br />
once you remove it, you cannot recall it back.</p>



<h2 class="wp-block-heading">SSH fail</h2>



<p>After reboot, Docker listen port will change, when ssh to docker, sometimes, it will show below error message<br /><br /></p>



<p>ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br />
ERROR: @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @<br />
ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br />
ERROR: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!<br />
ERROR: Someone could be eavesdropping on you right now (man-in-the-middle attack)!<br />
ERROR: It is also possible that a host key has just been changed.<br />
ERROR: The fingerprint for the RSA key sent by the remote host is<br />
ERROR: SHA256:le87dSbnHw6hmDCjqNF38wGgI3W95nvLLoDEgtfnNyY.<br />
ERROR: Please contact your system administrator.<br />
ERROR: Add correct host key in /home/username/.ssh/known_hosts to get rid of this message.<br />
ERROR: Offending RSA key in /home/username/.ssh/known_hosts:15<br />
ERROR: remove with:<br />
ERROR: ssh-keygen -f &#8220;/home/username/.ssh/known_hosts&#8221; -R &#8220;[localhost]:32769&#8221;<br />
ERROR: RSA host key for [localhost]:32769 has changed and you have requested strict checking.<br />
ERROR: Host key verification failed.<br />
Just run following command to remove it.</p>



<pre class="wp-block-preformatted">$ ssh-keygen -f "/home/username/.ssh/known_hosts" -R "[localhost]:32769"</pre>



<h2 class="wp-block-heading">Auto Start Docker Container When reboot</h2>



<p>Enable docker by default  </p>



<pre class="wp-block-preformatted">systemctl enable docker</pre>



<p>Change docker status to unless-stopped (ref. <a href="https://docs.docker.com/config/containers/start-containers-automatically/" target="_blank" rel="noopener">Start containers automatically</a>)</p>



<pre class="wp-block-preformatted">docker update --restart=unless-stopped sdk620</pre>



<h2 class="wp-block-heading">Ubuntu 18.04</h2>



<p><s>if rootfs is 18.04, there are some minor change between docker file.<br /> 1) Cannot use change root password to login system. reason unknown.<br /> 2) kernel package name is different<br /> 3) need to configure time-zone.<br />but it can use different way to login system : ssh login with key. it needs minor change to dockerfile.<br />if you don&#8217;t have ~/.ssh/ida_rsa and ~/.ssh/ida_rsa.pub file, it can generate ssh key with command and copy file to your docker folder.</s></p>



<pre class="wp-block-preformatted"><s>$ ssh-keygen
$ cp ~/.ssh/ida_rsa.pub [path to ubuntu 18.04 docker folder]</s></pre>



<p>following is docker 18.04 file , if you are not in Taiwan, please also change zoneinfo to your timezone accordingly.</p>



<pre class="wp-block-preformatted">FROM ubuntu:18.04

RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list

# RUN echo "Acquire::http::Proxy \"http://192.168.1.254:3142\";" &gt;&gt; /etc/apt/apt.conf

RUN apt-get update &amp;&amp; apt-get install -y openssh-server apt-utils
RUN mkdir -p /var/run/sshd

RUN export DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y tzdata
RUN ln -fs /usr/share/zoneinfo/Asia/Taiwan /etc/localtime
RUN dpkg-reconfigure --frontend noninteractive tzdata

RUN apt -y install vim tmux lftp net-tools ethtool bc sudo wget
RUN apt-get -y build-dep linux-image-generic
RUN apt install -y docbook-utils libncurses5-dev help2man texinfo m4 flex
RUN apt install -y bison autoconf libltdl-dev libltdl7 zlib1g-dev uuid-dev
RUN apt install -y pkg-config alien libglib2.0-dev pigz liblz4-tool
RUN apt install -y libssl-dev pkg-config aptitude m4 flex bison texinfo
RUN aptitude install -y liblz4-tool pandoc texlive-xetex device-tree-compiler

# it needs gmake to compile u-boot
RUN sudo ln -s /usr/bin/make /usr/bin/gmake

RUN apt -y upgrade
RUN apt autoclean

#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" &gt;&gt; /etc/profile
RUN sed -i "s/UsePAM yes/UsePAM no/" /etc/ssh/sshd_config
# ADD id_rsa.pub /root/.ssh/authorized_keys

EXPOSE 22
CMD bash /root/service.sh ; /usr/sbin/sshd -D</pre>
<p>The post <a rel="nofollow" href="https://richliu.com/2017/12/24/2199/build-sdk-in-docker/">Build SDK in Docker</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2017/12/24/2199/build-sdk-in-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
