Difference between revisions of "Docker Image for developing"

From ESS-WIKI
Jump to: navigation, search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
= MQTT BUS =
+
= Common Docker CLI =
<pre>sudo docker run -d -it --name advigw-mqtt-bus -p 1883:1883 advigw4x86/mqtt-bus</pre>
 
  
 +
<span style="font-size:large;">'''Docker Run - runs processes in isolated container&nbsp;[https://docs.docker.com/engine/reference/run/ option]'''</span>
  
 +
{| border="1" cellspacing="1" cellpadding="1" style="width:1000px;"
 +
|-
 +
| Option
 +
| style="width: 414px;" | Description
 +
| style="width: 172px;" | Note
 +
|-
 +
| -d
 +
| style="width: 414px;" | runs the container in the background
 +
| style="width: 172px;" | <br/>
 +
|-
 +
| -it
 +
| style="width: 414px;" | For interactive processes ( like a shell).<br/>
 +
| style="width: 172px;" | <br/>
 +
|-
 +
| --name
 +
| style="width: 414px;" | Container identification
 +
| style="width: 172px;" | <br/>
 +
|-
 +
| -p
 +
| style="width: 414px;" | export port&nbsp;&lt;host port&gt;:&lt;internal port&gt;
 +
| style="width: 172px;" | 80:3000
 +
|-
 +
| exec
 +
| style="width: 414px;" | run a command in a running container<br/>
 +
| style="width: 172px;" | <br/>
 +
|-
 +
| -v
 +
| style="width: 414px;" | volume ( shared filesystems ) e.g. -v [host-src]:[container-dest]:[option]<br/>
 +
| style="width: 172px;" | -v /run/udev:/run/udev:ro, -v $PWD:/home/adv:rw<br/>
 +
|-
 +
| --privileged<br/>
 +
| style="width: 414px;" | Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host<br/>
 +
| style="width: 172px;" | <br/>
 +
|}
  
= API-Gateway =
+
<span style="font-size:large;">'''Start a docker container and export server port'''</span>
<pre>sudo docker run -d -it --name advigw-api-gw -p 3000:3000 advigw4x86/api-gw</pre>
+
<pre>$sudo docker run -d -it --name advigw-mqtt-bus -p 1883:1883 advigw4x86/mqtt-bus
  
 +
$sudo docker run -d -it --name advigw-api-gw -p 3000:3000 advigw4x86/api-gw</pre>
  
  
= WISESnail lib/sample & Development "WSN Connectivity" environment =
 
<pre>sudo docker run -d -it --name advigw-wisesnail-lib-dev -v $PWD:/home/adv/workspace:rw advigw4x86/wisesnail-lib
 
  
sudo docker exec -it advigw-wisesnail-lib-dev bash</pre>
+
<span style="font-size:large;">'''Start a docker container and enter into bash'''</span>
 +
<pre>// need add -it
 +
// Run and enter to bash
 +
$sudo docker run -d -it --name advigw-wisesnail-lib-dev -v $PWD:/home/adv/workspace:rw advigw4x86/wisesnail-lib /bin/bash  
  
 +
// Enter a running container bash
 +
$sudo docker exec -it advigw-wisesnail-lib-dev bash</pre>
  
  
= WSN Simulator =
 
  
== Install & Run WSN Simulator ==
+
<span style="font-size:larger;">'''Stop /&nbsp;Start Docker Container'''</span>
<pre>sudo docker run -d -it --name advigw-wsn-simulator advigw4x86/wsn-simulator</pre>
+
<pre>$sudo docker stop advigw-wsn-simulator
  
== Stop /&nbsp;Start&nbsp;WSN Simulator ==
+
$sudo docker start advigw-wsn-simulator</pre>
<pre>sudo docker stop advigw-wsn-simulator
 
  
sudo docker start advigw-wsn-simulator</pre>
+
<span style="font-size:large;">'''Docker logs&nbsp;: redictor stdout&nbsp;'''</span>
 +
<pre>// dcoker logs container-name > log.txt
 +
$docker logs advigw-wsn-simulator > log.txt
 +
 
 +
// docker logs --follow container-name
 +
$docker logs --follow advigw-wsn-simulator</pre>
 +
 
 +
'''<span style="font-size:large;">Check Network of Container</span>'''
 +
<pre>$docker inspect <CONTAINER ID/NAME> | grep -w "IPAddress" | awk '{ print $2 }' | head -n 1 | cut -d "," -f1</pre>
 +
 
 +
<span style="font-size:large;">'''Show all create container service'''</span>
 +
<pre>$docker ps -a
 +
 
 +
CONTAINER ID        IMAGE                                  COMMAND                  CREATED            STATUS                      PORTS
 +
14df7ce9b276        elasticsearch                        "/docker-entrypoint.s"  8 days ago          Up 5 days                    0.0.0.0:9200->9200/tcp, 9300/tcp
 +
fb5f646cd1ac        debug/modbus                        "/usr/local/EService-"  3 weeks ago        Up 3 weeks
 +
ca0a5f11c3a8        eis/ensaas                          "/bin/bash"              6 months ago        Exited (0) 5 months ago
 +
 
 +
</pre>
 +
 
 +
= Dockerfile =
 +
 
 +
== build image ==
 +
 
 +
1. Prepare your Dockerfile - build command
 +
 
 +
docker build -t advigw4x86/wisesnail_dev .
 +
 
 +
advigw4x86/wisesnail_dev: docker image name
 +
 
 +
== alpine ==
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/mqtt-bus/Dockerfile https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/mqtt-bus/Dockerfile]
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/node-red/Dockerfile https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/node-red/Dockerfile]
 +
 
 +
== Ubuntu 16.04 ==
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/service-template/Dockerfile https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/service-template/Dockerfile]
 +
 
 +
= Docker Compose =
 +
 
 +
== Familiar CLI ==
 +
 
 +
{| border="1" cellspacing="1" cellpadding="1" style="width:700px;"
 +
|-
 +
| style="width: 144px;" | CLI
 +
| style="width: 278px;" | Description
 +
| style="width: 66px;" | Note
 +
|-
 +
| style="width: 144px;" | docker-compose up<br/>
 +
| style="width: 278px;" | creates ( pull ) and&nbsp;starts the containers<br/>
 +
| style="width: 66px;" | -d&nbsp;: in the background
 +
|-
 +
| style="width: 144px;" | docker-compose stop<br/>
 +
| style="width: 278px;" | stops running containers without removing them.<br/>
 +
| style="width: 66px;" | <br/>
 +
|-
 +
| style="width: 144px;" | docker-compose start<br/>
 +
| style="width: 278px;" | start existing containers for a service<br/>
 +
| style="width: 66px;" | <br/>
 +
|-
 +
| style="width: 144px;" | docker-compose down<br/>
 +
| style="width: 278px;" | Stops and removes containers, networks, volumes, and <span style="color:#FF0000;">images </span>created by up.<br/>
 +
| style="width: 66px;" | <br/>
 +
|-
 +
| style="width: 144px;" | docker-compose create<br/>
 +
| style="width: 278px;" | Creates containers for a service. == 'up' + '--no-start'<br/>
 +
| style="width: 66px;" | <br/>
 +
|-
 +
| style="width: 144px;" | docker-compose pause
 +
| style="width: 278px;" | Pauses running containers of a service.<br/>
 +
| style="width: 66px;" | <br/>
 +
|}
 +
 
 +
&nbsp; &nbsp; &nbsp;&nbsp;
 +
 
 +
== Example of yml&nbsp;file&nbsp; ==
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-edgesense-image-x86/blob/release/docker/advantech/edge-sense-services.yml https://github.com/ADVANTECH-Corp/docker-edgesense-image-x86/blob/release/docker/advantech/edge-sense-services.yml]
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/eis-base-service.yml https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/eis-base-service.yml]
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/wsn-dev.sh https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/wsn-dev.sh]
 +
 
 +
[https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/wsn-dust-link.yml https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/wsn-dust-link.yml]
  
  
Line 42: Line 163:
  
 
= [[How_to_create_a_Auto_Build_project_on_DockerHub_with_GitHub|How to create a Auto Build project on Docker hub with GitHub]] =
 
= [[How_to_create_a_Auto_Build_project_on_DockerHub_with_GitHub|How to create a Auto Build project on Docker hub with GitHub]] =
 
=  =
 
  
 
= Docker for Windows Hyper-V =
 
= Docker for Windows Hyper-V =
Line 51: Line 170:
  
  
https://docs.microsoft.com/zh-tw/virtualization/windowscontainers/manage-containers/container-networking
+
[https://docs.microsoft.com/zh-tw/virtualization/windowscontainers/manage-containers/container-networking https://docs.microsoft.com/zh-tw/virtualization/windowscontainers/manage-containers/container-networking]

Latest revision as of 11:26, 21 February 2022

Common Docker CLI

Docker Run - runs processes in isolated container option

Option Description Note
-d runs the container in the background
-it For interactive processes ( like a shell).

--name Container identification
-p export port <host port>:<internal port> 80:3000
exec run a command in a running container

-v volume ( shared filesystems ) e.g. -v [host-src]:[container-dest]:[option]
-v /run/udev:/run/udev:ro, -v $PWD:/home/adv:rw
--privileged
Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host

Start a docker container and export server port

$sudo docker run -d -it --name advigw-mqtt-bus -p 1883:1883 advigw4x86/mqtt-bus

$sudo docker run -d -it --name advigw-api-gw -p 3000:3000 advigw4x86/api-gw


Start a docker container and enter into bash

// need add -it
// Run and enter to bash
$sudo docker run -d -it --name advigw-wisesnail-lib-dev -v $PWD:/home/adv/workspace:rw advigw4x86/wisesnail-lib /bin/bash 

// Enter a running container bash
$sudo docker exec -it advigw-wisesnail-lib-dev bash


Stop / Start Docker Container

$sudo docker stop advigw-wsn-simulator

$sudo docker start advigw-wsn-simulator

Docker logs : redictor stdout 

// dcoker logs container-name > log.txt
$docker logs advigw-wsn-simulator > log.txt

// docker logs --follow container-name
$docker logs --follow advigw-wsn-simulator

Check Network of Container

$docker inspect <CONTAINER ID/NAME> | grep -w "IPAddress" | awk '{ print $2 }' | head -n 1 | cut -d "," -f1

Show all create container service

$docker ps -a

CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                       PORTS
14df7ce9b276        elasticsearch                        "/docker-entrypoint.s"   8 days ago          Up 5 days                    0.0.0.0:9200->9200/tcp, 9300/tcp
fb5f646cd1ac         debug/modbus                        "/usr/local/EService-"   3 weeks ago         Up 3 weeks
ca0a5f11c3a8        eis/ensaas                           "/bin/bash"              6 months ago        Exited (0) 5 months ago

Dockerfile

build image

1. Prepare your Dockerfile - build command

docker build -t advigw4x86/wisesnail_dev .

advigw4x86/wisesnail_dev: docker image name

alpine

https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/mqtt-bus/Dockerfile

https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/node-red/Dockerfile

Ubuntu 16.04

https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/service-template/Dockerfile

Docker Compose

Familiar CLI

CLI Description Note
docker-compose up
creates ( pull ) and starts the containers
-d : in the background
docker-compose stop
stops running containers without removing them.

docker-compose start
start existing containers for a service

docker-compose down
Stops and removes containers, networks, volumes, and images created by up.

docker-compose create
Creates containers for a service. == 'up' + '--no-start'

docker-compose pause Pauses running containers of a service.

      

Example of yml file 

https://github.com/ADVANTECH-Corp/docker-edgesense-image-x86/blob/release/docker/advantech/edge-sense-services.yml

https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/eis-base-service.yml

https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/wsn-dev.sh

https://github.com/ADVANTECH-Corp/docker-igw-image-x86/blob/installer/advantech/wsn-dust-link.yml


Network Configuration in Docker Container

 sudo docker network create -d bridge --subnet 172.25.0.0/16 advigw_network
 
 sudo docker network connect advigw_network advigw-mqtt-bus
 
 sudo docker network connect advigw_network advigw-api-gw
 
 sudo docker network connect advigw_network advigw-wisesnail-lib-dev

 sudo docker network connect advigw_network advigw-wsn-simulator


How to create a Auto Build project on Docker hub with GitHub

Docker for Windows Hyper-V

https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-networking


https://docs.microsoft.com/zh-tw/virtualization/windowscontainers/manage-containers/container-networking