using docker to develop nas applications

46
Using Docker to develop NAS application Terry Chen

Upload: terry-chen

Post on 15-Apr-2017

271 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Using docker to develop NAS applications

Using Docker to developNAS application

Terry Chen

Page 2: Using docker to develop NAS applications

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

Outline

● Introduce basic knowledge of Docker

● Using Docker to deploy NAS applications

Page 4: Using docker to develop NAS applications

What is container?

From : Macmillan Dictionary

Page 5: Using docker to develop NAS applications

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

Before container

From:https://en.wikipedia.org/wiki/Stevedore

Page 7: Using docker to develop NAS applications

With container

From : http://pointful.github.io/docker-intro/#/6

Page 8: Using docker to develop NAS applications

Other key property of container

Isolation

Page 9: Using docker to develop NAS applications

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

Application stack

OS Kernel

System libraries

Language runtime

Application code

Configuration

Page 11: Using docker to develop NAS applications

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

Virtual machine

OS Kernel

System libraries

Language runtime

Application code

Configuration

Page 13: Using docker to develop NAS applications

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

VM vs container

Page 15: Using docker to develop NAS applications

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

DEMO

Page 17: Using docker to develop NAS applications

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

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

DEMO

Page 20: Using docker to develop NAS applications

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

教練,我只想運作我的程式!!

Page 22: Using docker to develop NAS applications

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

Docker and Linux

From : https://en.wikipedia.org/wiki/Docker_(software)

Page 24: Using docker to develop NAS applications

Docker power

From : https://yq.aliyun.com/articles/32071

Dockerfile

Page 25: Using docker to develop NAS applications

Dockerfile

FROM alpine:3.3RUN apk add --no-cache nginx

Page 26: Using docker to develop NAS applications

Docker build my-nginx:0.1 image

FROM alpine:3.3RUN apk add --no-cache nginx

Page 27: Using docker to develop NAS applications

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

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

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

AUFS – Another Union File System

From : https://docs.docker.com/engine/userguide/storagedriver/aufs-driver/

Page 31: Using docker to develop NAS applications

DEMO

Page 32: Using docker to develop NAS applications

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

Stop container

my-nginx container

nginx: master process

nginx: worker process

Send SIGTERM

Page 34: Using docker to develop NAS applications

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

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

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

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

Container Station API

● Version V1.6.1600

Page 39: Using docker to develop NAS applications

DEMO

Page 40: Using docker to develop NAS applications

Common questions

Q: Can skip the initialization of Container Station ?

A: Using system-docker

Page 41: Using docker to develop NAS applications

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

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

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 44: Using docker to develop NAS applications

Common questions

Q: How to learn Docker ?

A: Docker Docs is your friend!

Page 45: Using docker to develop NAS applications

From : http://9gag.com/gag/anYZ9Eo/my-code-works-but-i-don-t-know-why

Page 46: Using docker to develop NAS applications

From: http://blog.octanner.com/wp-content/uploads/2013/12/thankyou.jpg