12. #container??
“Concept for create environment for software,
without disturbing the rest of the core operating system.”
Mr.Weerayut Hongsa - @kusumoto_ton
37. One Server Multiple Projects
Server
App 1
PHP
MySQL
Etc.
App 2
PHP
MariaDB
Etc.
App n
PHP
MySQL
Etc.
Mr.Weerayut Hongsa - @kusumoto_ton
38. One Server Multiple Projects
Server
App 1
PHP 5.2.1
MySQL 5.1
Etc.
App 2
PHP 5.5.3
MariaDB 10
Etc.
App n
PHP 7.0
MySQL 5.6
Etc.
Mr.Weerayut Hongsa - @kusumoto_ton
52. Can Docker help you?
• Docker can create environment compatible for your software.
• Docker separate disk space each project.
• You software easy for implementation.
• You software easy deployment and portability.
Mr.Weerayut Hongsa - @kusumoto_ton
69. Image
• Linux or Windows Inside.
• Already install the application and environment.
• Build from Dockerfile or container.
• After build image, the image can been read only.
• Template of container.
Mr.Weerayut Hongsa - @kusumoto_ton
70. Container
”Wrap up a piece of software in a complete filesystem
that contains everything it needs to run”
Mr.Weerayut Hongsa - @kusumoto_ton
71. Container
• Create from image.
• Running Process
• Can modify/access after container up and running
• Commit change to create image
Mr.Weerayut Hongsa - @kusumoto_ton
73. Registry
• Contain a lot of images.
• There are many services, Docker hub is key future.
• Image on registry can pull from any location.
Mr.Weerayut Hongsa - @kusumoto_ton
74. Image vs Container
• Compare the OOP concept (Image = Class, Container = Object)
• Image can't writable / Container can writeable
• Image can extends
• Image need transform to Container only for runnable.
Mr.Weerayut Hongsa - @kusumoto_ton
75. Next step, we talk about Docker
workflow.
Mr.Weerayut Hongsa - @kusumoto_ton
105. Create container from image and run container
docker run ubuntu:xenial /bin/echo “hello word”
Mr.Weerayut Hongsa - @kusumoto_ton
106. docker run ubuntu:xenial /bin/echo “hello word”
Image Name execute argument
Create container from image and run container
Mr.Weerayut Hongsa - @kusumoto_ton
107. docker run -d ubuntu:xenial /bin/echo “hello word”
Image Name execute argument
Create container from image and run container
parameter
Mr.Weerayut Hongsa - @kusumoto_ton
108. docker run ubuntu:xenial /bin/echo “hello word”
Create container from image and run container
Mr.Weerayut Hongsa - @kusumoto_ton
115. Create a new image from a container’s changes
docker commit d927d74ecd97 kusumoto/testhello:latest
Image NameContainer
Mr.Weerayut Hongsa - @kusumoto_ton
116. Create a new image from a container’s changes
docker commit d927d74ecd97 kusumoto/testhello:latest
Mr.Weerayut Hongsa - @kusumoto_ton
130. docker run -d kusumoto/docker-openresty:latest
Create container from image and run container
-d : run container in background mode
Mr.Weerayut Hongsa - @kusumoto_ton
131. docker run -d kusumoto/docker-openresty:latest
Create container from image and run container
Mr.Weerayut Hongsa - @kusumoto_ton
135. docker run -d -p 80:80 nginx:latest
Image Name
Create container and expose port to real host
Run container background
Expose port from container port 80 to local port 80 [local:container]
Mr.Weerayut Hongsa - @kusumoto_ton
136. docker run -d -p 80:80 nginx:latest
Create container and expose port to real host
Mr.Weerayut Hongsa - @kusumoto_ton
137. docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
Mapping host volume to container
Mr.Weerayut Hongsa - @kusumoto_ton
138. docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
Mapping host volume to container
Run container background
Expose port from container port 80 to local port 80 [local:container]
Image Name
Mapping volume to container [host:container]
Mr.Weerayut Hongsa - @kusumoto_ton
139. docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
Mapping host volume to container
Mr.Weerayut Hongsa - @kusumoto_ton
156. Run container and attach network
docker run -d --name nginx --net backend --ip="192.168.1.130" -p 80:8080 nginx
Mr.Weerayut Hongsa - @kusumoto_ton
157. Run container and attach network
docker run -d --name nginx --net backend --ip="192.168.1.130" -p 80:8080 nginx
Attach network to
container
Assign ip address to
container
Mr.Weerayut Hongsa - @kusumoto_ton
158. Run container and attach network
docker run -d --name nginx --net backend --ip="192.168.1.130" -p 80:8080 nginx
Mr.Weerayut Hongsa - @kusumoto_ton
159. Do you want to store and control
persistent data in container?
Mr.Weerayut Hongsa - @kusumoto_ton
160. Next step, we talk about #docker
Volume
Mr.Weerayut Hongsa - @kusumoto_ton
161. What is Docker Volume?
”Concept for manage persistent data in
container”
Mr.Weerayut Hongsa - @kusumoto_ton
162. Type of Data Volumes
• Mount a host directory as a data volume
• Mount a shared-storage volume as a data volume
• Mount a host file as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
163. Mount a host directory as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
164. docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
Run container background
Expose port from container port 80 to local port 80 [local:container]
Image Name
Mapping volume to container [host:container]
Mr.Weerayut Hongsa - @kusumoto_ton
Mount a host directory as a data volume
165. Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker volume create --driver=flocker volumename
166. Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker volume create --driver=flocker volumename
File System Driver
167. Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker container run -it –v volumename:/data busybox sh
168. Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker container run -it –v volumename:/data busybox sh
Mapping file to container [share-storage:container]
169. Mount a host file as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash
170. Mount a host file as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash
Mapping file to container [host:container]
171. Do you want make an easy to control
multiple #docker node?
Mr.Weerayut Hongsa - @kusumoto_ton
196. What is Docker Compose?
”A tool for defining and running multi-
container Docker applications.”
Mr.Weerayut Hongsa - @kusumoto_ton
197. Docker Compose
• A template for create and configuration container
• YML format
• Up and running in one command
• Update all container in one command
Mr.Weerayut Hongsa - @kusumoto_ton
220. Docker Swarm
• Scalable container to multiple docker node.
• Control container multiple docker node via docker swarm manager.
• In Docker swarm, you’ll have some new concepts of “services” and “tasks”.
Mr.Weerayut Hongsa - @kusumoto_ton
231. Create new service in swarm cluster
docker service create --name nginx-web -p 80:80 nginx:latest
Mr.Weerayut Hongsa - @kusumoto_ton
232. Create new service in swarm cluster
docker service create --name nginx-web -p 80:80 nginx:latest
Image Name
Expose port from service port 80 to local port 80 [local:container]
Service name
Mr.Weerayut Hongsa - @kusumoto_ton
233. Create new service in swarm cluster
docker service create --name nginx-web -p 80:80 nginx:latest
Mr.Weerayut Hongsa - @kusumoto_ton
234. List all service in swarm cluster
docker service ls
Mr.Weerayut Hongsa - @kusumoto_ton
235. List all service in swarm cluster
docker service ls
Mr.Weerayut Hongsa - @kusumoto_ton
236. Scale up/down service in swarm cluster
docker service scale nginx=3
Mr.Weerayut Hongsa - @kusumoto_ton
237. Scale up/down service in swarm cluster
docker service scale nginx=3
Service name
Number of container
Mr.Weerayut Hongsa - @kusumoto_ton
238. Scale up/down service in swarm cluster
docker service scale nginx=3
Mr.Weerayut Hongsa - @kusumoto_ton
239. Update/Apply service in swarm cluster
docker service update nginx
Mr.Weerayut Hongsa - @kusumoto_ton
240. Update/Apply service in swarm cluster
docker service update nginx
Service name
Mr.Weerayut Hongsa - @kusumoto_ton
241. Update/Apply service in swarm cluster
docker service update nginx
Mr.Weerayut Hongsa - @kusumoto_ton
242. Delete service in swarm cluster
docker service rm nginx
Mr.Weerayut Hongsa - @kusumoto_ton
243. Delete service in swarm cluster
docker service rm nginx
Service name
Mr.Weerayut Hongsa - @kusumoto_ton
244. Delete service in swarm cluster
docker service rm nginx
Mr.Weerayut Hongsa - @kusumoto_ton
245. Add service stack from docker-compose.yml to swarm
cluster
docker stack deploy --compose-file docker-compose.yml my_stack
Mr.Weerayut Hongsa - @kusumoto_ton
246. Add service stack from docker-compose.yml to swarm
cluster
docker stack deploy --compose-file docker-compose.yml my_stack
Compose file Stack name
Mr.Weerayut Hongsa - @kusumoto_ton
247. Add service stack from docker-compose.yml to swarm
cluster
docker stack deploy --compose-file docker-compose.yml my_stack
Mr.Weerayut Hongsa - @kusumoto_ton