Difference between revisions of "IoTGateway/Docker"

From ESS-WIKI
Jump to: navigation, search
(Undo revision 4919 by Alex.cheng (talk))
m (Reverted edits by Alex.cheng (talk) to last revision by Daniel.hung)
Line 1: Line 1:
 
Use Docker to set up build environment more safely & quickly
 
Use Docker to set up build environment more safely & quickly
  
== Overview ==
+
==Overview==
 +
To deliver a clean build environment for customer development, we are used to provide a VMWare image. However, this kind of hypervisor mechanism is bigger and always comes worse performance.<ref name="ref1" /> Fortunately, we have an alternative way for this now. We put the build environment into a container. In a container, performance for building process is similar as native computer<ref name="ref2" />, and it also provides process isolation & resource limitation for security and stability.
  
To deliver a clean build environment for customer development, we are used to provide a VMWare image. However, this kind of hypervisor mechanism is bigger and always comes worse performance.<ref name="ref1">_</ref> Fortunately, we have an alternative way for this now. We put the build environment into a container. In a container, performance for building process is similar as native computer<ref name="ref2">_</ref>, and it also provides process isolation & resource limitation for security and stability.
 
  
 
We adopt [https://www.docker.com/ Docker] to achieve this feature.
 
We adopt [https://www.docker.com/ Docker] to achieve this feature.
  
== Requirement ==
+
==Requirement==
 
+
Before you use Docker to develop, you have to install Docker on your platform. Please refer to [https://docs.docker.com/engine/installation/ Docker Installation Guide]. You are able to install Docker on Linux, Cloud, Windows, and OS X. In general, you may choose to install on ''Ubuntu''.<ref name="ref3" />
Before you use Docker to develop, you have to install Docker on your platform. Please refer to [https://docs.docker.com/engine/installation/ Docker Installation Guide]. You are able to install Docker on Linux, Cloud, Windows, and OS X. In general, you may choose to install on ''Ubuntu''.<ref name="ref3">_</ref>
 
 
 
== Usage ==
 
  
 +
==Usage==
 
If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:
 
If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:
 
 
  $ sudo usermod -aG docker $your_user
 
  $ sudo usermod -aG docker $your_user
 
 
''Note: You may need to login again to activate.''
 
''Note: You may need to login again to activate.''
 
+
===Get base image===
=== Get base image ===
+
To get the images we provided, you can use ''docker pull <IMAGE REPOSITORY>'' to get the images in the ''[[#Image List | image list]]''.
 
 
To get the images we provided, you can use ''docker pull &lt;IMAGE REPOSITORY&gt;'' to get the images in the ''[[#Image_List|image list]]''.
 
  
 
  $ docker pull advrisc/u12.04-imx6lbv3:20160303
 
  $ docker pull advrisc/u12.04-imx6lbv3:20160303
Line 51: Line 45:
  
 
You can check the image stored locally by ''docker images''.
 
You can check the image stored locally by ''docker images''.
 
 
  $ docker images
 
  $ docker images
 
  REPOSITORY                              TAG                IMAGE ID            CREATED            VIRTUAL SIZE
 
  REPOSITORY                              TAG                IMAGE ID            CREATED            VIRTUAL SIZE
 
  advrisc/u12.04-imx6lbv3                  20160303            92116cadf140        30 minutes ago      1.443 GB
 
  advrisc/u12.04-imx6lbv3                  20160303            92116cadf140        30 minutes ago      1.443 GB
  
=== Create a container ===
+
===Create a container===
 
 
 
You can create a new container with a prompt by ''docker run''. If you did not ''pull'' the Docker base image before, it will try to download it from the DockerHub repository first.
 
You can create a new container with a prompt by ''docker run''. If you did not ''pull'' the Docker base image before, it will try to download it from the DockerHub repository first.
  
Line 65: Line 57:
  
 
To leave a container, type ''exit'' to stop it or use '''''Ctrl + P + Q''''' to detach the container.
 
To leave a container, type ''exit'' to stop it or use '''''Ctrl + P + Q''''' to detach the container.
 
 
  adv@89e9548a0d40:~$ exit
 
  adv@89e9548a0d40:~$ exit
 
  exit
 
  exit
  
 
You can check the container status by ''docker ps''.
 
You can check the container status by ''docker ps''.
 
 
  $ docker ps -a
 
  $ docker ps -a
 
  CONTAINER ID    IMAGE                              COMMAND        CREATED            STATUS                      PORTS    NAMES
 
  CONTAINER ID    IMAGE                              COMMAND        CREATED            STATUS                      PORTS    NAMES
 
  89e9548a0d40    advrisc/u12.04-imx6lbv3:20160303  "/bin/bash"    27 seconds ago    Exited (0) 4 seconds ago              dreamy_jennings
 
  89e9548a0d40    advrisc/u12.04-imx6lbv3:20160303  "/bin/bash"    27 seconds ago    Exited (0) 4 seconds ago              dreamy_jennings
  
To enter the container that you've created, you need to do ''docker start &lt;CONTAINER ID&gt;'' & ''docker attach &lt;CONTAINER ID&gt;''.
+
To enter the container that you've created, you need to do ''docker start <CONTAINER ID>'' & ''docker attach <CONTAINER ID>''.
 
 
 
  $ docker start 89e9548a0d40
 
  $ docker start 89e9548a0d40
 
  89e9548a0d40
 
  89e9548a0d40
Line 83: Line 72:
 
  adv@89e9548a0d40:~$
 
  adv@89e9548a0d40:~$
  
=== Share data with host ===
+
===Share data with host===
 
 
 
There are two ways to share data with host OS.
 
There are two ways to share data with host OS.
 +
* data volume
 +
* docker cp
  
*data volume
 
*docker cp
 
  
 
You have to assign data volumes when creating the container. Use ''docker run'' with '''-v''' options to enable data volume. In the case below, we mount the BSP directory (/home/root/imx6LBV5080_2016-02-03) from your Docker daemon’s host into a container. So, you can access the source code at /home/adv/BSP in the container.
 
You have to assign data volumes when creating the container. Use ''docker run'' with '''-v''' options to enable data volume. In the case below, we mount the BSP directory (/home/root/imx6LBV5080_2016-02-03) from your Docker daemon’s host into a container. So, you can access the source code at /home/adv/BSP in the container.
 
 
  $ docker run -it --name docker_test -v /home/root/imx6LBV5080_2016-02-03:/home/adv/BSP:rw advrisc/u12.04-imx6lbv3:20160303 /bin/bash
 
  $ docker run -it --name docker_test -v /home/root/imx6LBV5080_2016-02-03:/home/adv/BSP:rw advrisc/u12.04-imx6lbv3:20160303 /bin/bash
 
   
 
   
Line 97: Line 84:
 
  adv@7bc2d878c870:~$ sudo chown adv:adv -R BSP
 
  adv@7bc2d878c870:~$ sudo chown adv:adv -R BSP
  
Alternatively, you can also access data in containers after the container is created. Use ''docker cp &lt;CONTAINER:PATH&gt; &lt;LOCALPATH&gt;'' to pull out data from the container, or ''docker cp &lt;LOCALPATH&gt; &lt;CONTAINER:PATH&gt;'' to push data into the container.
+
Alternatively, you can also access data in containers after the container is created. Use ''docker cp <CONTAINER:PATH> <LOCALPATH>'' to pull out data from the container, or ''docker cp <LOCALPATH> <CONTAINER:PATH>'' to push data into the container.
  
 
  // Copy sdcard image from container to host
 
  // Copy sdcard image from container to host
Line 105: Line 92:
 
  $ docker cp imx6LBV5080_2016-02-03.tgz 89e9548a0d40:/home/adv
 
  $ docker cp imx6LBV5080_2016-02-03.tgz 89e9548a0d40:/home/adv
  
=== Remove image or container ===
+
===Remove image or container===
 
+
Once you do not need the container, you can use ''docker rm <CONTAINER ID>'' to remove it.
Once you do not need the container, you can use ''docker rm &lt;CONTAINER ID&gt;'' to remove it.
 
 
 
 
  $ docker rm 89e9548a0d40
 
  $ docker rm 89e9548a0d40
 
  89e9548a0d40
 
  89e9548a0d40
  
If you want to remove Docker base image, use ''docker rmi &lt;IMAGE ID&gt;''
+
If you want to remove Docker base image, use ''docker rmi <IMAGE ID>''
 
 
 
  $ docker rmi advrisc/u12.04-imx6lbv3:20160303
 
  $ docker rmi advrisc/u12.04-imx6lbv3:20160303
  
== BSP Building ==
+
==BSP Building==
 
 
 
It's very easy to build our BSP in Docker environment.
 
It's very easy to build our BSP in Docker environment.
 +
# Get BSP source code
 +
# Run a Docker container with data volume sharing for the BSP, or you can use ''docker cp'' to put BSP into the container.
 +
# In the container, go to BSP folder and follow the same introductions as you do on normal computer.
 +
# Finally, copy your images from container to host.
  
#Get BSP source code
+
==Image List==
#Run a Docker container with data volume sharing for the BSP, or you can use ''docker cp'' to put BSP into the container.
 
#In the container, go to BSP folder and follow the same introductions as you do on normal computer.
 
#Finally, copy your images from container to host.
 
 
 
== Image List ==
 
 
 
 
All our images are stored in [https://hub.docker.com/explore/ DockerHub]. You can explore and find the image as listed below.
 
All our images are stored in [https://hub.docker.com/explore/ DockerHub]. You can explore and find the image as listed below.
 
 
{| class="wikitable" style="text-align: center; width: 800px;"
 
{| class="wikitable" style="text-align: center; width: 800px;"
|-
 
 
! Image Repository
 
! Image Repository
 
! Image Tag
 
! Image Tag
Line 139: Line 118:
 
| 20160303
 
| 20160303
 
| Ubuntu 12.04
 
| Ubuntu 12.04
| Freescale i.MX6 Yocto 1.5 (fsl-yocto-3.10.17_1.0.x)<br/>Freescale i.MX6 Yocto 1.7 (fsl-yocto-3.14.28_1.0.0)<br/>Freescale i.MX6 Yocto 1.8 (fsl-yocto-3.14.52_1.1.0)<br/>Freescale i.MX6 Yocto 2.0 (fsl-yocto-4.1.15_1.1.0)
+
| Freescale i.MX6 Yocto 1.5 (fsl-yocto-3.10.17_1.0.x)<br>Freescale i.MX6 Yocto 1.7 (fsl-yocto-3.14.28_1.0.0)<br>Freescale i.MX6 Yocto 1.8 (fsl-yocto-3.14.52_1.1.0)<br>Freescale i.MX6 Yocto 2.0 (fsl-yocto-4.1.15_1.1.0)
 
|-
 
|-
 
| [https://hub.docker.com/r/advrisc/u12.04-quarklbv2 advrisc/u12.04-quarklbv2]
 
| [https://hub.docker.com/r/advrisc/u12.04-quarklbv2 advrisc/u12.04-quarklbv2]
 
| 20160621
 
| 20160621
 
| Ubuntu 12.04
 
| Ubuntu 12.04
| Intel Quark Yocto 1.4.2 (Intel Quark BSP 1.0.4)<br/>Intel Quark Yocto 1.7.2 (Intel Quark BSP 1.2.0)
+
| Intel Quark Yocto 1.4.2 (Intel Quark BSP 1.0.4)<br>Intel Quark Yocto 1.7.2 (Intel Quark BSP 1.2.0)
 
|-
 
|-
 
| [https://hub.docker.com/r/advrisc/u12.04-imx6abv1 advrisc/u12.04-imx6abv1]
 
| [https://hub.docker.com/r/advrisc/u12.04-imx6abv1 advrisc/u12.04-imx6abv1]
Line 154: Line 133:
 
| 20160809
 
| 20160809
 
| Ubuntu 12.04
 
| Ubuntu 12.04
| Freescale i.MX6 Android 4.3 (android_JB4.3_1.1.0)<br/>Freescale i.MX6 Android 4.4.2 (android_KK4.4.2_1.0.0)
+
| Freescale i.MX6 Android 4.3 (android_JB4.3_1.1.0)<br>Freescale i.MX6 Android 4.4.2 (android_KK4.4.2_1.0.0)
 
|-
 
|-
 
| [https://hub.docker.com/r/advrisc/u14.04-imx6abv4 advrisc/u14.04-imx6abv4]
 
| [https://hub.docker.com/r/advrisc/u14.04-imx6abv4 advrisc/u14.04-imx6abv4]
 
| 20160825
 
| 20160825
 
| Ubuntu 14.04
 
| Ubuntu 14.04
| Freescale i.MX6 Android 5.0.0 (android_L5.0.0_1.0.0)<br/>Freescale i.MX6 Android 5.1.1 (android_L5.1.1_2.1.0)<br/>Freescale i.MX6 Android 6.0.1 (android_M6.0.1_1.0.0)
+
| Freescale i.MX6 Android 5.0.0 (android_L5.0.0_1.0.0)<br>Freescale i.MX6 Android 5.1.1 (android_L5.1.1_2.1.0)<br>Freescale i.MX6 Android 6.0.1 (android_M6.0.1_1.0.0)
 
|-
 
|-
 
| [https://hub.docker.com/r/advrisc/u14.04-410clbv1 advrisc/u14.04-410clbv1]
 
| [https://hub.docker.com/r/advrisc/u14.04-410clbv1 advrisc/u14.04-410clbv1]
Line 167: Line 146:
 
|}
 
|}
  
== Customization ==
+
==Customization==
 
+
You can use [https://docs.docker.com/engine/reference/builder/ Dockerfile] to create your own base image.
You can use [https://docs.docker.com/engine/reference/builder/ Dockerfile] to create your own base image. Your Dockerfile may looks like this.
+
Your Dockerfile may looks like this.
 
 
 
  FROM advrisc/u12.04-imx6lbv3
 
  FROM advrisc/u12.04-imx6lbv3
 
   
 
   
Line 185: Line 163:
  
 
Then, you can use ''docker build'' to generate a new base image with tag.
 
Then, you can use ''docker build'' to generate a new base image with tag.
 
 
  $ cd <the-folder-which-has-Dockerfile>
 
  $ cd <the-folder-which-has-Dockerfile>
 
  $ docker build -t vendor/new-base-image .
 
  $ docker build -t vendor/new-base-image .
  
== References ==
+
==References==
 
+
<references>
<references />
+
<ref name="ref1">[http://bodenr.blogspot.tw/2014/05/kvm-and-docker-lxc-benchmarking-with.html Differences between Docker, LXC & Hypervisor (Chinese)]</ref>
 
+
<ref name="ref2">[http://blog.pierreroudier.net/2015/08/docker-vs-kvm-vs-native-performance-comparison/ Docker Performance]</ref>
*External Link
+
<ref name="ref3">[https://docs.docker.com/engine/installation/linux/ubuntulinux/ Docker Installation on Ubuntu]</ref>
 +
</references>
 +
* External Link
 +
# [https://philipzheng.gitbooks.io/docker_practice/content/index.html Docker Introduction (Chinese)]
  
#[https://philipzheng.gitbooks.io/docker_practice/content/index.html Docker Introduction (Chinese)]
 
 
[[Category:Technique]]
 
[[Category:Technique]]

Revision as of 11:05, 9 January 2017

Use Docker to set up build environment more safely & quickly

Overview

To deliver a clean build environment for customer development, we are used to provide a VMWare image. However, this kind of hypervisor mechanism is bigger and always comes worse performance.[1] Fortunately, we have an alternative way for this now. We put the build environment into a container. In a container, performance for building process is similar as native computer[2], and it also provides process isolation & resource limitation for security and stability.


We adopt Docker to achieve this feature.

Requirement

Before you use Docker to develop, you have to install Docker on your platform. Please refer to Docker Installation Guide. You are able to install Docker on Linux, Cloud, Windows, and OS X. In general, you may choose to install on Ubuntu.[3]

Usage

If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:

$ sudo usermod -aG docker $your_user

Note: You may need to login again to activate.

Get base image

To get the images we provided, you can use docker pull <IMAGE REPOSITORY> to get the images in the image list.

$ docker pull advrisc/u12.04-imx6lbv3:20160303

20160303: Pulling from advrisc/u12.04-imx6lbv3
6df68bc875bf: Pull complete
20f5595aa1a4: Pull complete
93b424f526d8: Pull complete
c877b3e9524f: Pull complete
29a731492f99: Pull complete
3701b127b54b: Pull complete
15247541bc49: Pull complete
729f8eff6afb: Pull complete
130b818ebc2f: Pull complete
7239f480205c: Pull complete
fbcbd43c9696: Pull complete
3f211662827e: Pull complete
65fa0f0910df: Pull complete
fda959c610b9: Pull complete
85fd678cfd54: Pull complete
0c63b8fa6a0f: Pull complete
87e1750c6c91: Pull complete
837fb16417bc: Pull complete
d72b58a6026b: Pull complete
597115359768: Pull complete
92116cadf140: Pull complete
Digest: sha256:603bff4244d016d8318c59218296dc145fd32f7e4f8f4f5c94decca11941dbdf
Status: Downloaded newer image for advrisc/u12.04-imx6lbv3:20160303

You can check the image stored locally by docker images.

$ docker images
REPOSITORY                               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
advrisc/u12.04-imx6lbv3                  20160303            92116cadf140        30 minutes ago      1.443 GB

Create a container

You can create a new container with a prompt by docker run. If you did not pull the Docker base image before, it will try to download it from the DockerHub repository first.

$ docker run -it advrisc/u12.04-imx6lbv3:20160303 /bin/bash

adv@89e9548a0d40:~$

To leave a container, type exit to stop it or use Ctrl + P + Q to detach the container.

adv@89e9548a0d40:~$ exit
exit

You can check the container status by docker ps.

$ docker ps -a
CONTAINER ID     IMAGE                              COMMAND        CREATED            STATUS                      PORTS     NAMES
89e9548a0d40     advrisc/u12.04-imx6lbv3:20160303   "/bin/bash"    27 seconds ago     Exited (0) 4 seconds ago              dreamy_jennings

To enter the container that you've created, you need to do docker start <CONTAINER ID> & docker attach <CONTAINER ID>.

$ docker start 89e9548a0d40
89e9548a0d40

$ docker attach 89e9548a0d40
adv@89e9548a0d40:~$

Share data with host

There are two ways to share data with host OS.

  • data volume
  • docker cp


You have to assign data volumes when creating the container. Use docker run with -v options to enable data volume. In the case below, we mount the BSP directory (/home/root/imx6LBV5080_2016-02-03) from your Docker daemon’s host into a container. So, you can access the source code at /home/adv/BSP in the container.

$ docker run -it --name docker_test -v /home/root/imx6LBV5080_2016-02-03:/home/adv/BSP:rw advrisc/u12.04-imx6lbv3:20160303 /bin/bash

// Let adv get access permission
adv@7bc2d878c870:~$ sudo chown adv:adv -R BSP

Alternatively, you can also access data in containers after the container is created. Use docker cp <CONTAINER:PATH> <LOCALPATH> to pull out data from the container, or docker cp <LOCALPATH> <CONTAINER:PATH> to push data into the container.

// Copy sdcard image from container to host
$ docker cp 89e9548a0d40:/home/adv/imx6LBV5080_2016-02-03/build_all/tmp/deploy/images/imx6qrsb4410/fsl-image-x11-imx6qrsb4410.sdcard .

// Copy BSP source code into container
$ docker cp imx6LBV5080_2016-02-03.tgz 89e9548a0d40:/home/adv

Remove image or container

Once you do not need the container, you can use docker rm <CONTAINER ID> to remove it.

$ docker rm 89e9548a0d40
89e9548a0d40

If you want to remove Docker base image, use docker rmi <IMAGE ID>

$ docker rmi advrisc/u12.04-imx6lbv3:20160303

BSP Building

It's very easy to build our BSP in Docker environment.

  1. Get BSP source code
  2. Run a Docker container with data volume sharing for the BSP, or you can use docker cp to put BSP into the container.
  3. In the container, go to BSP folder and follow the same introductions as you do on normal computer.
  4. Finally, copy your images from container to host.

Image List

All our images are stored in DockerHub. You can explore and find the image as listed below.

Image Repository Image Tag Base OS Supported Platforms
advrisc/u12.04-imx6lbv3 20160303 Ubuntu 12.04 Freescale i.MX6 Yocto 1.5 (fsl-yocto-3.10.17_1.0.x)
Freescale i.MX6 Yocto 1.7 (fsl-yocto-3.14.28_1.0.0)
Freescale i.MX6 Yocto 1.8 (fsl-yocto-3.14.52_1.1.0)
Freescale i.MX6 Yocto 2.0 (fsl-yocto-4.1.15_1.1.0)
advrisc/u12.04-quarklbv2 20160621 Ubuntu 12.04 Intel Quark Yocto 1.4.2 (Intel Quark BSP 1.0.4)
Intel Quark Yocto 1.7.2 (Intel Quark BSP 1.2.0)
advrisc/u12.04-imx6abv1 20160713 Ubuntu 12.04 Freescale i.MX6 Android 4.2 (android_JB4.2.2_1.1.0)
advrisc/u12.04-imx6abv2 20160809 Ubuntu 12.04 Freescale i.MX6 Android 4.3 (android_JB4.3_1.1.0)
Freescale i.MX6 Android 4.4.2 (android_KK4.4.2_1.0.0)
advrisc/u14.04-imx6abv4 20160825 Ubuntu 14.04 Freescale i.MX6 Android 5.0.0 (android_L5.0.0_1.0.0)
Freescale i.MX6 Android 5.1.1 (android_L5.1.1_2.1.0)
Freescale i.MX6 Android 6.0.1 (android_M6.0.1_1.0.0)
advrisc/u14.04-410clbv1 20160919 Ubuntu 14.04 Qualcomm db410c Yocto 2.0 (oe-rpb-manifest jethro)

Customization

You can use Dockerfile to create your own base image. Your Dockerfile may looks like this.

FROM advrisc/u12.04-imx6lbv3

MAINTAINER Vendor's Company

WORKDIR /
USER root

# The packages you want to install
RUN apt-get install -y NewPackages

WORKDIR /home/adv
USER adv

Then, you can use docker build to generate a new base image with tag.

$ cd <the-folder-which-has-Dockerfile>
$ docker build -t vendor/new-base-image .

References

  1. Differences between Docker, LXC & Hypervisor (Chinese)
  2. Docker Performance
  3. Docker Installation on Ubuntu
  • External Link
  1. Docker Introduction (Chinese)