using docker to develop nas applications
TRANSCRIPT
![Page 1: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/1.jpg)
Using Docker to developNAS application
Terry Chen
![Page 2: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/2.jpg)
About me
● Backend engineer : Java, Python, Linux
● QNAP Container Station/Linux Station
https://www.linkedin.com/in/seterrychen
https://github.com/seterrychen
https://twitter.com/seterrychen
![Page 3: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/3.jpg)
Outline
● Introduce basic knowledge of Docker
● Using Docker to deploy NAS applications
![Page 4: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/4.jpg)
What is container?
From : Macmillan Dictionary
![Page 5: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/5.jpg)
What is container?
From : Macmillan Dictionary From : http://www.containerhireaust.com.au/containers/20-foot-general-purpose/
![Page 6: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/6.jpg)
Before container
From:https://en.wikipedia.org/wiki/Stevedore
![Page 7: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/7.jpg)
With container
From : http://pointful.github.io/docker-intro/#/6
![Page 8: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/8.jpg)
Other key property of container
Isolation
![Page 9: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/9.jpg)
Deploy software
From : https://goo.gl/YIKVMJ http://www.hive-io.com/virtual-server-infrastructure/
Development Environment Production Environment
![Page 10: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/10.jpg)
Application stack
OS Kernel
System libraries
Language runtime
Application code
Configuration
![Page 11: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/11.jpg)
Container concept in software engineering
From : http://www.vccoaching.com/smarter-thinking/ http://pclosmag.com/html/Issues/201304/page08.html
OS Kernel
System libraries
Language runtime
Application code
Configuration
![Page 12: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/12.jpg)
Virtual machine
OS Kernel
System libraries
Language runtime
Application code
Configuration
![Page 13: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/13.jpg)
Linux Container (LXC)
OS Kernel
System libraries
Language runtime
Application code
Configuration
System libraries
Language runtime
Application code
Configuration
System libraries
Language runtime
Application code
Configuration
System libraries
Language runtime
Application code
Configuration
![Page 14: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/14.jpg)
VM vs container
![Page 15: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/15.jpg)
Basic isolation of Linux
● chroot : A chroot on Unix operating systems is an operation that changes the apparent root directory for the current running process and its children.
From : http://freedompenguin.com/articles/how-to/learning-the-linux-file-system/
![Page 16: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/16.jpg)
DEMO
![Page 17: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/17.jpg)
Isolation of LXC
● Linux Kernel feature :○ Namespaces
■ Mount namespaces■ UTS namespaces■ IPC namespaces■ PID namespaces■ Network namespaces■ User namespaces
![Page 18: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/18.jpg)
Tools of LXC
● lxc-create : download base rootfs and create a container● lxc-start, lxc-stop … : control the container● lxc-attach : start a process inside a running container● lxc-ls : list all containers status
![Page 19: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/19.jpg)
DEMO
![Page 20: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/20.jpg)
Pain point when using LXC (in my case)
● Install your application by script
● Deploy containers by manual
● No version control system/repositories to store containers you already install
application
From : http://icons.iconarchive.com/icons/babasse/imod/72/Tar-icon.png
Host 1 Host 2
container-v1.0 container-v2.0 container-v3.0 container-v1.0 container-v1.1
![Page 21: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/21.jpg)
教練,我只想運作我的程式!!
![Page 22: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/22.jpg)
What is Docker ?
Docker is an open-source engine which automates the deployment of applications as highly portable, self-sufficient containers.
(From : https://github.com/docker/docker/wiki/Docker-0.3.0-release-note,-May-6-2013)
![Page 23: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/23.jpg)
Docker and Linux
From : https://en.wikipedia.org/wiki/Docker_(software)
![Page 24: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/24.jpg)
Docker power
From : https://yq.aliyun.com/articles/32071
Dockerfile
![Page 25: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/25.jpg)
Dockerfile
FROM alpine:3.3RUN apk add --no-cache nginx
![Page 26: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/26.jpg)
Docker build my-nginx:0.1 image
FROM alpine:3.3RUN apk add --no-cache nginx
![Page 27: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/27.jpg)
Docker build my-nginx:0.1 image
FROM alpine:3.3RUN apk add --no-cache nginx
From : http://thepapist.org/ask-a-question/
![Page 28: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/28.jpg)
Layers of My-nginx image (Docker version 1.9)
0dcd4549ae28 4.797 MB
ff2b369bf5c3 1.454 MB
Image : my-nginx:0.1FROM alpine:3.3RUN apk add --no-cache nginx
![Page 29: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/29.jpg)
Docker image / container
0dcd4549ae28 4.797 MB
ff2b369bf5c3 1.454 MB
Image : my-nginx:0.1
Container
mount
![Page 30: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/30.jpg)
AUFS – Another Union File System
From : https://docs.docker.com/engine/userguide/storagedriver/aufs-driver/
![Page 31: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/31.jpg)
DEMO
![Page 32: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/32.jpg)
Process inside container
my-nginx container
nginx: master process
nginx: worker process
PID 1
host
nginx: master process
nginx: worker process
PID 5566
![Page 33: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/33.jpg)
Stop container
my-nginx container
nginx: master process
nginx: worker process
Send SIGTERM
![Page 34: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/34.jpg)
Install dockerized application by qpkg
● For example : Redmine ( docker-qdk2 )
├── icons
├── package_routines
├── qpkg.cfg
├── shared
│ ├── docker-compose.yml
│ ├── redmine.conf
│ └── redmine.sh
└── x86_64
![Page 35: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/35.jpg)
docker-composepostgresql: image: sameersbn/postgresql:9.4-11 environment: - DB_USER=redmine - DB_PASS=password - DB_NAME=redmine_productionredmine: image: sameersbn/redmine:3.2.0-1 links: - postgresql:postgresql environment: - REDMINE_PORT=10083 - REDMINE_RELATIVE_URL_ROOT=/redmine ports: - "127.0.0.1:10083:80"
![Page 36: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/36.jpg)
Redmine.conf
ProxyRequests off
ProxyPass /redmine/ http://127.0.0.1:10083/redmine/
ProxyPassReverse /redmine/ http://127.0.0.1:10083/redmine/
![Page 37: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/37.jpg)
Package_routines
pkg_post_install() {
…..
DEPEND_ON=container-station
/sbin/setcfg $QPKG_NAME depend_on "${DEPEND_ON}" -f /etc/config/qpkg.conf
/sbin/log_tool -t0 -uSystem -p127.0.0.1 -mlocalhost -a "[$QPKG_NAME] Start installation"
$CONTAINER_STATION/bin/qbus post com.qnap.dqpkg/qpkg '{"qpkg": "'$QPKG_NAME'",
"action": "install"}'
}
![Page 38: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/38.jpg)
Container Station API
● Version V1.6.1600
![Page 39: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/39.jpg)
DEMO
![Page 40: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/40.jpg)
Common questions
Q: Can skip the initialization of Container Station ?
A: Using system-docker
![Page 41: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/41.jpg)
Common questions
Q: Why is a container suddenly closed after executing docker run ?
A: The PID 1 process inside container is closed. Please using bash replace the default command to debug.
![Page 42: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/42.jpg)
Common questions
Q: How to backup data of a container
A: Using docker run -v /host_path/backup:/container_path/data
![Page 43: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/43.jpg)
Common questions
Q: At container, how to get information of NAS
A: Using docker -v /host/your_socket:/container/run.
Example : -v /etc/qbus:/etc/qbus -v /var/run/qbus.sock:/var/run/qbus.sock -v /share/CACHEDEV2_DATA/.qpkg/container-station/usr/bin/.libs/qbus:/bin/qbus
![Page 45: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/45.jpg)
From : http://9gag.com/gag/anYZ9Eo/my-code-works-but-i-don-t-know-why
![Page 46: Using docker to develop NAS applications](https://reader034.vdocuments.site/reader034/viewer/2022042707/587e942f1a28ab672b8b64c7/html5/thumbnails/46.jpg)
From: http://blog.octanner.com/wp-content/uploads/2013/12/thankyou.jpg