using docker to develop nas applications
TRANSCRIPT
Using Docker to developNAS application
Terry Chen
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
Outline
● Introduce basic knowledge of Docker
● Using Docker to deploy NAS applications
What is container?
From : Macmillan Dictionary
What is container?
From : Macmillan Dictionary From : http://www.containerhireaust.com.au/containers/20-foot-general-purpose/
Before container
From:https://en.wikipedia.org/wiki/Stevedore
With container
From : http://pointful.github.io/docker-intro/#/6
Other key property of container
Isolation
Deploy software
From : https://goo.gl/YIKVMJ http://www.hive-io.com/virtual-server-infrastructure/
Development Environment Production Environment
Application stack
OS Kernel
System libraries
Language runtime
Application code
Configuration
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
Virtual machine
OS Kernel
System libraries
Language runtime
Application code
Configuration
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
VM vs container
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/
DEMO
Isolation of LXC
● Linux Kernel feature :○ Namespaces
■ Mount namespaces■ UTS namespaces■ IPC namespaces■ PID namespaces■ Network namespaces■ User namespaces
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
DEMO
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
教練,我只想運作我的程式!!
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)
Docker and Linux
From : https://en.wikipedia.org/wiki/Docker_(software)
Docker power
From : https://yq.aliyun.com/articles/32071
Dockerfile
Dockerfile
FROM alpine:3.3RUN apk add --no-cache nginx
Docker build my-nginx:0.1 image
FROM alpine:3.3RUN apk add --no-cache nginx
Docker build my-nginx:0.1 image
FROM alpine:3.3RUN apk add --no-cache nginx
From : http://thepapist.org/ask-a-question/
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
Docker image / container
0dcd4549ae28 4.797 MB
ff2b369bf5c3 1.454 MB
Image : my-nginx:0.1
Container
mount
AUFS – Another Union File System
From : https://docs.docker.com/engine/userguide/storagedriver/aufs-driver/
DEMO
Process inside container
my-nginx container
nginx: master process
nginx: worker process
PID 1
host
nginx: master process
nginx: worker process
PID 5566
Stop container
my-nginx container
nginx: master process
nginx: worker process
Send SIGTERM
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
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"
Redmine.conf
ProxyRequests off
ProxyPass /redmine/ http://127.0.0.1:10083/redmine/
ProxyPassReverse /redmine/ http://127.0.0.1:10083/redmine/
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"}'
}
Container Station API
● Version V1.6.1600
DEMO
Common questions
Q: Can skip the initialization of Container Station ?
A: Using system-docker
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.
Common questions
Q: How to backup data of a container
A: Using docker run -v /host_path/backup:/container_path/data
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
From : http://9gag.com/gag/anYZ9Eo/my-code-works-but-i-don-t-know-why
From: http://blog.octanner.com/wp-content/uploads/2013/12/thankyou.jpg