Difference between revisions of "IoTGateway/Docker"

From ESS-WIKI
Jump to: navigation, search
Line 12: Line 12:
 
==Usage==
 
==Usage==
 
===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 <IMAGE REPOSITORY>'' to get the images in the ''[[#Image List | image list]]''.
  
  $ docker pull advrisc/u12.04
+
  $ docker pull advrisc/u12.04-imx6lbv3:20160303
 
   
 
   
  Using default tag: latest
+
  20160303: Pulling from advrisc/u12.04-imx6lbv3
latest: Pulling from advrisc/u12.04
+
  6df68bc875bf: Pull complete
  f371838f5dfc: Pull complete
+
  20f5595aa1a4: Pull complete
  ba07dd60c647: Pull complete
+
  93b424f526d8: Pull complete
  5880097ae715: Pull complete
+
  c877b3e9524f: Pull complete
  f4661df611e4: Pull complete
+
  29a731492f99: Pull complete
  54a5be518f6c: Pull complete
+
  3701b127b54b: Pull complete
  e2bec7aca208: Pull complete
+
  15247541bc49: Pull complete
  2329df4bbef8: Pull complete
+
  729f8eff6afb: Pull complete
  8c316cbbf1ac: Pull complete
+
  130b818ebc2f: Pull complete
  759306f82120: Pull complete
+
  7239f480205c: Pull complete
  129b531714c2: Pull complete
+
  fbcbd43c9696: Pull complete
  9785b9285b43: Pull complete
+
  3f211662827e: Pull complete
  4edbf4b599cd: Pull complete
+
  65fa0f0910df: Pull complete
  6662a831b325: Pull complete
+
  fda959c610b9: Pull complete
  69b5c4a73004: Pull complete
+
  85fd678cfd54: Pull complete
  2356632c3d7c: Pull complete
+
  0c63b8fa6a0f: Pull complete
  7de0ecf5853e: Pull complete
+
  87e1750c6c91: Pull complete
  437e96edde13: Pull complete
+
  837fb16417bc: Pull complete
  71b22a0603c5: Pull complete
+
  d72b58a6026b: Pull complete
  81f2b54bc89e: Pull complete
+
  597115359768: Pull complete
  45223227ca23: Pull complete
+
  92116cadf140: Pull complete
  e088fe2feb22: Pull complete
+
  Digest: sha256:603bff4244d016d8318c59218296dc145fd32f7e4f8f4f5c94decca11941dbdf
  Digest: sha256:10f22a1cfbb657b8db267860773078fc09118604b421d47e260dac7c4fa04099
+
  Status: Downloaded newer image for advrisc/u12.04-imx6lbv3:20160303
  Status: Image is up to date for advrisc/u12.04:latest
 
  
 
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                           latest              e088fe2feb22       59 minutes ago      1.438 GB
+
  advrisc/u12.04-imx6lbv3                  20160303            92116cadf140       30 minutes ago      1.443 GB
  
 
===Create a container===
 
===Create a container===
 
You can run a container with a prompt by ''docker run''. If you do not pull Docker base image first, it will try to download from the DockerHub repository.
 
You can run a container with a prompt by ''docker run''. If you do not pull Docker base image first, it will try to download from the DockerHub repository.
  
  $ docker run -it advrisc/u12.04 /bin/bash
+
  $ docker run -it advrisc/u12.04-imx6lbv3:20160303 /bin/bash
 
   
 
   
  adv@d0ab7f662fb3:~$
+
  adv@89e9548a0d40:~$
  
 
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@d0ab7f662fb3:~$ 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
  d0ab7f662fb3        advrisc/u12.04       "/bin/bash"         3 minutes ago       Exited (0) 4 seconds ago                   clever_bartik
+
  89e9548a0d40    advrisc/u12.04-imx6lbv3:20160303  "/bin/bash"   27 seconds ago     Exited (0) 4 seconds ago             dreamy_jennings
  
 
To enter the container again, you need to do ''docker start <CONTAINER ID>'' & ''docker attach <CONTAINER ID>''.
 
To enter the container again, you need to do ''docker start <CONTAINER ID>'' & ''docker attach <CONTAINER ID>''.
  $ docker start d0ab7f662fb3
+
  $ docker start 89e9548a0d40
  d0ab7f662fb3
+
  89e9548a0d40
 
   
 
   
  $ docker attach d0ab7f662fb3
+
  $ docker attach 89e9548a0d40
  adv@d0ab7f662fb3:~$
+
  adv@89e9548a0d40:~$
  
 
===Share data with host===
 
===Share data with host===
Line 77: Line 76:
  
 
Use ''docker run'' with '''-v''' options to enable data volume. In the case below, we mount a host directory (/home/root) from your Docker daemon’s host into a container. So, you can access the contents in /home/adv in the container.
 
Use ''docker run'' with '''-v''' options to enable data volume. In the case below, we mount a host directory (/home/root) from your Docker daemon’s host into a container. So, you can access the contents in /home/adv in the container.
  $ docker run -it --name docker_test -v /home/root:/home/adv advrisc/u12.04 /bin/bash
+
  $ docker run -it --name docker_test -v /home/root:/home/adv advrisc/u12.04-imx6lbv3:20160303 /bin/bash
 
   
 
   
 
  adv@7bc2d878c870:~$
 
  adv@7bc2d878c870:~$
Line 83: Line 82:
 
Alternatively, you can 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.
 
Alternatively, you can 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.
  
  $ docker cp d0ab7f662fb3:/home/adv/test.jpg .
+
  $ docker cp 89e9548a0d40:/home/adv/test.jpg .
 
   
 
   
  $ docker cp ./test.png d0ab7f662fb3:/home/adv
+
  $ docker cp ./test.png 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 <CONTAINER ID>'' to remove it.
  $ docker rm d0ab7f662fb3
+
  $ docker rm 89e9548a0d40
  d0ab7f662fb3
+
  89e9548a0d40
  
 
If you want to remove Docker base image, use ''docker rmi <IMAGE ID>''
 
If you want to remove Docker base image, use ''docker rmi <IMAGE ID>''
  $ docker rmi advrisc/u12.04
+
  $ docker rmi advrisc/u12.04-imx6lbv3:20160303
  
 
==BSP Building==
 
==BSP Building==
Line 104: Line 103:
 
==Image List==
 
==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: 600px;"
+
{| class="wikitable" style="text-align: center; width: 800px;"
 
! Image Repository
 
! Image Repository
 
! Image Tag
 
! Image Tag
Line 110: Line 109:
 
! Supported Platforms
 
! Supported Platforms
 
|-
 
|-
| [https://hub.docker.com/r/advrisc/u12.04/ advrisc/u12.04]
+
| [https://hub.docker.com/r/advrisc/u12.04-imx6lbv3 advrisc/u12.04-imx6lbv3]
| latest
+
| 20160303
 
| Ubuntu 12.04
 
| Ubuntu 12.04
| Freescale i.MX6 Yocto 1.5
+
| Freescale i.MX6 Yocto 1.5 (fsl-yocto-3.10.17_1.0.x)
 
|}
 
|}
  

Revision as of 04:12, 3 March 2016

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

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 run a container with a prompt by docker run. If you do not pull Docker base image first, it will try to download from the DockerHub repository.

$ 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 again, 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


Use docker run with -v options to enable data volume. In the case below, we mount a host directory (/home/root) from your Docker daemon’s host into a container. So, you can access the contents in /home/adv in the container.

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

adv@7bc2d878c870:~$

Alternatively, you can 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.

$ docker cp 89e9548a0d40:/home/adv/test.jpg .

$ docker cp ./test.png 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)

References

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