Date post: | 05-Apr-2017 |
Category: |
Technology |
Upload: | weerayut-hongsa |
View: | 803 times |
Download: | 0 times |
DockerFor Developer
#whoami• Mr. Weerayut Hongsa (@kusumoto_ton)• Graduated from Prince of Songkla University, Phuket Campus
Major Software Engineer• System Administrator / Infrastructure Engineer
(Major Kantana Broadcasting Co., Ltd)• Software Developer (C#, Node.js, Lua, Java, PHP, Javascript)
#Freelance• Software Developer (iCONEXT Co., Ltd)• Interesting DevOps, Software Development, Agile Methodology,
CI/CD, Infrastructure As a Code
#resourcehttps://github.com/Kusumoto/psu-docker-workshop-resource
What is Docker ?
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
This is “Dock” :p
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
#docker??
“Software Container management platform”
Mr.Weerayut Hongsa - @kusumoto_ton
#docker??
Mr.Weerayut Hongsa - @kusumoto_ton
What is Container ?
Mr.Weerayut Hongsa - @kusumoto_ton
#container??
“Concept for create environment for software, without disturbing the rest of the core operating system.”
Mr.Weerayut Hongsa - @kusumoto_ton
#container??
Mr.Weerayut Hongsa - @kusumoto_ton
Why to use Docker?
Mr.Weerayut Hongsa - @kusumoto_ton
Ok, I have a new question.Do you have this problem?
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
FTP
Mr.Weerayut Hongsa - @kusumoto_ton
FTP
Mr.Weerayut Hongsa - @kusumoto_ton
FTP
Mr.Weerayut Hongsa - @kusumoto_ton
FTP??
?
Mr.Weerayut Hongsa - @kusumoto_ton
FTP??
? Software version is not been control.
Mr.Weerayut Hongsa - @kusumoto_ton
I would say that, Docker can solve all problem.
Mr.Weerayut Hongsa - @kusumoto_ton
#docker platform
Docker Engine Docker Machine Docker Compose Docker Swarm Docker Registry
Mr.Weerayut Hongsa - @kusumoto_ton
Why not use VM (Virtual Machine) ?
Mr.Weerayut Hongsa - @kusumoto_ton
Virtual Machine (VM) Containers (Docker)
#teamvm vs #teamcontainer
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Mr.Weerayut Hongsa - @kusumoto_ton
#docker edition
• Community Edition (CE)• Enterprise Edition (EE)
Mr.Weerayut Hongsa - @kusumoto_ton
Case Study (Development Case)PHP Web Application Development
Mr.Weerayut Hongsa - @kusumoto_ton
PHP version requirement
yii2
CodeIgniterPhalcon
SymfonyLaravel
dokuwiki
Wordpress
Drupal 7 Drupal 8
Joomla
Mr.Weerayut Hongsa - @kusumoto_ton
PHP version requirement
yii2 (PHP 5.4+)
CodeIgniter (PHP 5.6+) Phalcon (PHP 5.5+)
Symfony (PHP 5.5.9+) Laravel (PHP 5.6.4+)
dokuwiki (PHP 5.3.4+)
Wordpress (PHP 5.2.4+)
Drupal 7 (PHP 5.2.5+) Drupal 8 (PHP 5.5.9+)
Joomla (PHP 5.3.10+)
Mr.Weerayut Hongsa - @kusumoto_ton
PHP version requirement
yii2 (PHP 5.4+)
CodeIgniter (PHP 5.6+) Phalcon (PHP 5.5+)
Symfony (PHP 5.5.9+) Laravel (PHP 5.6.4+)
dokuwiki (PHP 5.3.4+)
Wordpress (PHP 5.2.4+)
Drupal 7 (PHP 5.2.5+) Drupal 8 (PHP 5.5.9+)
Joomla (PHP 5.3.10+)
Mr.Weerayut Hongsa - @kusumoto_ton
PHP Extensionapxs2, mongo, db2, bcmath, bz2, calendar, cgi, cli, ctype, dab, debug, odbc, dom, embed, exif, fileinfo, filter, fpm, ftp, gcov, gd, gettext, hash, iconv, icu, imap, intl, ipc, ipv6, json, kerberos, mbregex, mbstring, mcrypt, mhash, mysql, openssl, pcntl, pcre, pdo, pgsql, phar, posix, readline, session, soap, sockets, sqlite, tidy, tokenize, xml_all, xmlrpc, zip, zlib
Mr.Weerayut Hongsa - @kusumoto_ton
PHP Extensionapxs2, mongo, db2, bcmath, bz2, calendar, cgi, cli, ctype, dab, debug, odbc, dom, embed, exif, fileinfo, filter, fpm, ftp, gcov, gd, gettext, hash, iconv, icu, imap, intl, ipc, ipv6, json, kerberos, mbregex, mbstring, mcrypt, mhash, mysql, openssl, pcntl, pcre, pdo, pgsql, phar, posix, readline, session, soap, sockets, sqlite, tidy, tokenize, xml_all, xmlrpc, zip, zlib
Mr.Weerayut Hongsa - @kusumoto_ton
One Server Multiple Projects
Server
App 1PHPMySQLEtc.
App 2PHPMariaDBEtc.
App nPHPMySQLEtc.
Mr.Weerayut Hongsa - @kusumoto_ton
One Server Multiple Projects
Server
App 1PHP 5.2.1MySQL 5.1Etc.
App 2PHP 5.5.3MariaDB 10Etc.
App nPHP 7.0MySQL 5.6Etc.
Mr.Weerayut Hongsa - @kusumoto_ton
Mr.Weerayut Hongsa - @kusumoto_ton
Solve this problem!
Mr.Weerayut Hongsa - @kusumoto_ton
Virtual Machine (VM)
Mr.Weerayut Hongsa - @kusumoto_ton
Virtual Machine (VM)Can solve this problem
Mr.Weerayut Hongsa - @kusumoto_ton
Virtual Machine (VM)Can solve this problem
But not lightweight and use much more resources
Mr.Weerayut Hongsa - @kusumoto_ton
PHPBrew
Mr.Weerayut Hongsa - @kusumoto_ton
PHPBrewAlmost good
Mr.Weerayut Hongsa - @kusumoto_ton
PHPBrewAlmost good
But we need encapsulation, portability and portable
Mr.Weerayut Hongsa - @kusumoto_ton
Vagrant
Mr.Weerayut Hongsa - @kusumoto_ton
VagrantThat’s awesome!
Mr.Weerayut Hongsa - @kusumoto_ton
VagrantThat’s awesome!
But may it be more lightweight and portable
Mr.Weerayut Hongsa - @kusumoto_ton
Docker
Mr.Weerayut Hongsa - @kusumoto_ton
DockerThat’s awesome!
Lightweight, encapsulation, portability and portable
Mr.Weerayut Hongsa - @kusumoto_ton
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
PHP Multi Version In One Server
Mr.Weerayut Hongsa - @kusumoto_ton
Case Study (Operations Case)Large Scale Web Application
Mr.Weerayut Hongsa - @kusumoto_ton
It's time to deployment
Mr.Weerayut Hongsa - @kusumoto_ton
Basic Infrastructure
Mr.Weerayut Hongsa - @kusumoto_ton
Basic Infrastructure
Mr.Weerayut Hongsa - @kusumoto_ton
Basic Infrastructure
Mr.Weerayut Hongsa - @kusumoto_ton
Cloud InfrastructureBlock Storage
Cluster Farm
Mr.Weerayut Hongsa - @kusumoto_ton
Cloud InfrastructureBlock Storage
Cluster Farm
Mr.Weerayut Hongsa - @kusumoto_ton
Cloud InfrastructureBlock Storage
Cluster Farm
Mr.Weerayut Hongsa - @kusumoto_ton
Cloud InfrastructureBlock Storage
Cluster Farm
Mr.Weerayut Hongsa - @kusumoto_ton
Who’s using #docker?
Mr.Weerayut Hongsa - @kusumoto_ton
How do you know software support #docker?
Mr.Weerayut Hongsa - @kusumoto_ton
How do you know software support #docker?
Mr.Weerayut Hongsa - @kusumoto_ton
We talk about an element of Docker.
Mr.Weerayut Hongsa - @kusumoto_ton
Element of Docker
Registry (Docker Repository)ContainerImage
Mr.Weerayut Hongsa - @kusumoto_ton
Image
”A template of container”
Mr.Weerayut Hongsa - @kusumoto_ton
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
Container
”Wrap up a piece of software in a complete filesystem that contains everything it needs to run”
Mr.Weerayut Hongsa - @kusumoto_ton
Container
• Create from image.• Running Process• Can modify/access after container up and running• Commit change to create image
Mr.Weerayut Hongsa - @kusumoto_ton
Registry
”The repository of images”
Mr.Weerayut Hongsa - @kusumoto_ton
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
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
Next step, we talk about Docker workflow.
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
PULL
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container
PULL
RUN
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSH
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSH
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Dockerfile
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile Image
(from registry)PUSH
BUILD
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Mr.Weerayut Hongsa - @kusumoto_ton
Go back to #docker solution.
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSHBuild
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSHShip
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSHRun
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Build
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Ship
Mr.Weerayut Hongsa - @kusumoto_ton
#docker solution
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Run
Mr.Weerayut Hongsa - @kusumoto_ton
Do you understand #dockerworkflow and #docker solution?
Mr.Weerayut Hongsa - @kusumoto_ton
Next step, we talk about #dockercommand
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSH
Mr.Weerayut Hongsa - @kusumoto_ton
Pull image from repository to localdocker pull ubuntu:xenial
Mr.Weerayut Hongsa - @kusumoto_ton
Pull image from repository to localdocker pull ubuntu:xenial
Image Name
Mr.Weerayut Hongsa - @kusumoto_ton
Pull image from repository to localdocker pull ubuntu:xenial
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSH
Mr.Weerayut Hongsa - @kusumoto_ton
Create container from image and run container
docker run ubuntu:xenial /bin/echo “hello word”
Mr.Weerayut Hongsa - @kusumoto_ton
docker run ubuntu:xenial /bin/echo “hello word”
Image Name execute argument
Create container from image and run container
Mr.Weerayut Hongsa - @kusumoto_ton
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
docker run ubuntu:xenial /bin/echo “hello word”
Create container from image and run container
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSH
Mr.Weerayut Hongsa - @kusumoto_ton
List containerdocker ps
Mr.Weerayut Hongsa - @kusumoto_ton
List containerdocker ps
Mr.Weerayut Hongsa - @kusumoto_ton
List container (include stopped)docker ps -a
Mr.Weerayut Hongsa - @kusumoto_ton
List imagesdocker images
Mr.Weerayut Hongsa - @kusumoto_ton
List imagesdocker images
Mr.Weerayut Hongsa - @kusumoto_ton
Create a new image from a container’s changes
docker commit d927d74ecd97 kusumoto/testhello:latest
Image NameContainer
Mr.Weerayut Hongsa - @kusumoto_ton
Create a new image from a container’s changes
docker commit d927d74ecd97 kusumoto/testhello:latest
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from registry)
Image(from local)
Container Container (changed)
PULL
RUN
CHANGE
COMMIT
PUSH
Mr.Weerayut Hongsa - @kusumoto_ton
Push imagedocker push kusumoto/testhello:latest
Mr.Weerayut Hongsa - @kusumoto_ton
Push imagedocker push kusumoto/testhello:latest
Image Name (Match on repository)
Mr.Weerayut Hongsa - @kusumoto_ton
Push imagedocker push kusumoto/testhello:latest
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Mr.Weerayut Hongsa - @kusumoto_ton
Build image from Dockerfiledocker build -t kusumoto/tutu-bigo-tofblive .
Mr.Weerayut Hongsa - @kusumoto_ton
Build image from Dockerfiledocker build -t kusumoto/tutu-bigo-tofblive .
Image Name Path Dockerfileparameter
Mr.Weerayut Hongsa - @kusumoto_ton
Build image from Dockerfiledocker build -t kusumoto/tutu-bigo-tofblive .
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Mr.Weerayut Hongsa - @kusumoto_ton
Push imagedocker push kusumoto/tutu-bigo-tofblive:latest
Mr.Weerayut Hongsa - @kusumoto_ton
Push imagedocker push kusumoto/tutu-bigo-tofblive:latest
Image Name (Match on repository)
Mr.Weerayut Hongsa - @kusumoto_ton
Push imagedocker push kusumoto/tutu-bigo-tofblive:latest
Mr.Weerayut Hongsa - @kusumoto_ton
#docker workflow
Image(from local)Dockerfile
BUILD
Image(from registry)
PUSH
PULL
Container
RUN
Mr.Weerayut Hongsa - @kusumoto_ton
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
docker run -d kusumoto/docker-openresty:latest
Create container from image and run container
Mr.Weerayut Hongsa - @kusumoto_ton
Utility Command
Mr.Weerayut Hongsa - @kusumoto_ton
docker exec -it 158b4a099baf bash
Execute shell into container
Mr.Weerayut Hongsa - @kusumoto_ton
docker exec -it 158b4a099baf bash
Execute shell into container
Mr.Weerayut Hongsa - @kusumoto_ton
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
docker run -d -p 80:80 nginx:latest
Create container and expose port to real host
Mr.Weerayut Hongsa - @kusumoto_ton
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
docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
Mapping host volume to container
Run container backgroundExpose port from container port 80 to local port 80 [local:container]
Image Name
Mapping volume to container [host:container]
Mr.Weerayut Hongsa - @kusumoto_ton
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
docker system prune
System cleanup
Mr.Weerayut Hongsa - @kusumoto_ton
docker system prune
System cleanup
Mr.Weerayut Hongsa - @kusumoto_ton
docker login
Registry Authentication
Mr.Weerayut Hongsa - @kusumoto_ton
docker login
Registry Authentication
Mr.Weerayut Hongsa - @kusumoto_ton
Do you want to encapsulate your container?
Mr.Weerayut Hongsa - @kusumoto_ton
Next step, we talk about #dockernetwork
Mr.Weerayut Hongsa - @kusumoto_ton
What is Docker Network?
”Control communicate between container”
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Network
Mr.Weerayut Hongsa - @kusumoto_ton
Create new #docker networkdocker network create --driver bridge --subnet=192.168.1.0/24 --ip-range=192.168.1.128/25 --gateway=192.168.1.5 --opt="com.docker.network.mtu"="1500" backend
Mr.Weerayut Hongsa - @kusumoto_ton
Create new #docker networkdocker network create --driver bridge --subnet=192.168.1.0/24 --ip-range=192.168.1.128/25 --gateway=192.168.1.5 --opt="com.docker.network.mtu"="1500" backend
Network driver Network subnet IP range for container use.Gateway for
master subnet Network name
Mr.Weerayut Hongsa - @kusumoto_ton
Create new #docker networkdocker network create --driver bridge --subnet=192.168.1.0/24 --ip-range=192.168.1.128/25 --gateway=192.168.1.5 --opt="com.docker.network.mtu"="1500" backend
Mr.Weerayut Hongsa - @kusumoto_ton
List all #docker networkdocker network ls
Mr.Weerayut Hongsa - @kusumoto_ton
List all #docker networkdocker network ls
Mr.Weerayut Hongsa - @kusumoto_ton
Delete #docker networkdocker network rm backend
Mr.Weerayut Hongsa - @kusumoto_ton
Delete #docker networkdocker network rm backend
Network name
Mr.Weerayut Hongsa - @kusumoto_ton
Delete #docker networkdocker network rm backend
Mr.Weerayut Hongsa - @kusumoto_ton
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
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
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
Do you want to store and control persistent data in container?
Mr.Weerayut Hongsa - @kusumoto_ton
Next step, we talk about #dockerVolume
Mr.Weerayut Hongsa - @kusumoto_ton
What is Docker Volume?”Concept for manage persistent data in
container”
Mr.Weerayut Hongsa - @kusumoto_ton
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
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
docker run -d -v /home/kusumoto/test:/usr/share/nginx/html -p 80:80 nginx:latest
Run container backgroundExpose 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
Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker volume create --driver=flocker volumename
Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker volume create --driver=flocker volumename
File System Driver
Mount a share-storage as a data volume
Mr.Weerayut Hongsa - @kusumoto_ton
docker container run -it –v volumename:/data busybox sh
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]
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
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]
Do you want make an easy to control multiple #docker node?
Mr.Weerayut Hongsa - @kusumoto_ton
We’re recommend “Docker Machine”
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Machine is attached from Docker Toolbox
Mr.Weerayut Hongsa - @kusumoto_ton
What is Docker Machine?
”The tool for management #docker node”
Mr.Weerayut Hongsa - @kusumoto_ton
Create new #docker nodedocker-machine create --driver virtualbox node1
Machine Name
Driver for connect
Mr.Weerayut Hongsa - @kusumoto_ton
Driver for docker-machine are support
Mr.Weerayut Hongsa - @kusumoto_ton
Create new #docker nodedocker-machine create --driver virtualbox node1
Mr.Weerayut Hongsa - @kusumoto_ton
List #docker nodedocker-machine ls
Mr.Weerayut Hongsa - @kusumoto_ton
List #docker nodedocker-machine ls
Mr.Weerayut Hongsa - @kusumoto_ton
Start #docker node by docker-machine
docker-machine start node1
Mr.Weerayut Hongsa - @kusumoto_ton
Start #docker node by docker-machine
docker-machine start node1
Machine Name
Mr.Weerayut Hongsa - @kusumoto_ton
Start #docker node by docker-machine
docker-machine start node1
Mr.Weerayut Hongsa - @kusumoto_ton
Stop #docker node by docker-machine
docker-machine stop node1
Mr.Weerayut Hongsa - @kusumoto_ton
Stop #docker node by docker-machine
docker-machine stop node1
Machine Name
Mr.Weerayut Hongsa - @kusumoto_ton
Stop #docker node by docker-machine
docker-machine stop node1
Mr.Weerayut Hongsa - @kusumoto_ton
Remove #docker nodedocker-machine rm node1
Mr.Weerayut Hongsa - @kusumoto_ton
Remove #docker nodedocker-machine rm node1
Machine Name
Mr.Weerayut Hongsa - @kusumoto_ton
Remove #docker nodedocker-machine rm node1
Mr.Weerayut Hongsa - @kusumoto_ton
Show docker-machine environmentdocker-machine env
Mr.Weerayut Hongsa - @kusumoto_ton
Show docker-machine environmentdocker-machine env
Mr.Weerayut Hongsa - @kusumoto_ton
Connect shell to you #docker nodeeval "$(docker-machine env node1)"
Mr.Weerayut Hongsa - @kusumoto_ton
Connect shell to you #docker nodeeval "$(docker-machine env node1)"
Mr.Weerayut Hongsa - @kusumoto_ton
Do you think the container management very difficult?
Mr.Weerayut Hongsa - @kusumoto_ton
Have a tooling for container management make an easy?
Mr.Weerayut Hongsa - @kusumoto_ton
We’re recommend “Docker Compose”
Mr.Weerayut Hongsa - @kusumoto_ton
What is Docker Compose?
”A tool for defining and running multi-container Docker applications.”
Mr.Weerayut Hongsa - @kusumoto_ton
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
Example docker-compose.ymlversion: '2'services:web:build: .ports:- "5000:5000"volumes:- .:/code
redis:image: "redis:alpine"
Mr.Weerayut Hongsa - @kusumoto_ton
Command for execute docker-compose
Mr.Weerayut Hongsa - @kusumoto_ton
Up all container in docker-compose.ymldocker-compose up -d
Mr.Weerayut Hongsa - @kusumoto_ton
Up all container in docker-compose.ymldocker-compose up -d
Run all container in background
Mr.Weerayut Hongsa - @kusumoto_ton
Up all container in docker-compose.ymldocker-compose up -d
Mr.Weerayut Hongsa - @kusumoto_ton
Down all container in docker-compose.yml
docker-compose down
Mr.Weerayut Hongsa - @kusumoto_ton
Down all container in docker-compose.yml
docker-compose down
Mr.Weerayut Hongsa - @kusumoto_ton
List container in docker-compose stack
docker-compose ps
Mr.Weerayut Hongsa - @kusumoto_ton
List container in docker-compose stack
docker-compose ps
Mr.Weerayut Hongsa - @kusumoto_ton
If your application have a many current user?
Mr.Weerayut Hongsa - @kusumoto_ton
Do you want to scale your application?
Mr.Weerayut Hongsa - @kusumoto_ton
We’re recommend “Docker Swarm”
Mr.Weerayut Hongsa - @kusumoto_ton
You can scale container to multiple machine via Docker Swarm
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
How can you control cluster?
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
Choose a once node promote to manager
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
Manager
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
ManagerNode Node Node Node
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
ManagerNode Node Node Node
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
Mr.Weerayut Hongsa - @kusumoto_ton
Docker Swarm
”Run the Docker in cluster mode”
Mr.Weerayut Hongsa - @kusumoto_ton
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
Initialize Docker Swarmdocker swarm init
Mr.Weerayut Hongsa - @kusumoto_ton
Initialize Docker Swarmdocker swarm init
Mr.Weerayut Hongsa - @kusumoto_ton
Initialize Docker Swarmdocker swarm init
Command for join to swarm
Mr.Weerayut Hongsa - @kusumoto_ton
Join node to your Docker Swarmdocker swarm join --token SWMTKN-1-3o58oh8ahb0ebzqen63pp8dub4u91oqfy4erenaswbulih1ywr-4xr2p6ipg2tqxeczw6cp183ob 192.168.99.100:2377
Mr.Weerayut Hongsa - @kusumoto_ton
Join node to your Docker Swarmdocker swarm join --token SWMTKN-1-3o58oh8ahb0ebzqen63pp8dub4u91oqfy4erenaswbulih1ywr-4xr2p6ipg2tqxeczw6cp183ob 192.168.99.100:2377
IP Address swarm manager
Token
Mr.Weerayut Hongsa - @kusumoto_ton
Join node to your Docker Swarmdocker swarm join --token SWMTKN-1-3o58oh8ahb0ebzqen63pp8dub4u91oqfy4erenaswbulih1ywr-4xr2p6ipg2tqxeczw6cp183ob 192.168.99.100:2377
Mr.Weerayut Hongsa - @kusumoto_ton
List all node list and node statusdocker node ls
Mr.Weerayut Hongsa - @kusumoto_ton
List all node list and node statusdocker node ls
Mr.Weerayut Hongsa - @kusumoto_ton
Leave node from swarm clusterdocker swarm leave
Mr.Weerayut Hongsa - @kusumoto_ton
Leave node from swarm clusterdocker swarm leave
Mr.Weerayut Hongsa - @kusumoto_ton
Create new service in swarm clusterdocker service create --name nginx-web -p 80:80 nginx:latest
Mr.Weerayut Hongsa - @kusumoto_ton
Create new service in swarm clusterdocker 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
Create new service in swarm clusterdocker service create --name nginx-web -p 80:80 nginx:latest
Mr.Weerayut Hongsa - @kusumoto_ton
List all service in swarm clusterdocker service ls
Mr.Weerayut Hongsa - @kusumoto_ton
List all service in swarm clusterdocker service ls
Mr.Weerayut Hongsa - @kusumoto_ton
Scale up/down service in swarm clusterdocker service scale nginx=3
Mr.Weerayut Hongsa - @kusumoto_ton
Scale up/down service in swarm clusterdocker service scale nginx=3
Service name
Number of container
Mr.Weerayut Hongsa - @kusumoto_ton
Scale up/down service in swarm clusterdocker service scale nginx=3
Mr.Weerayut Hongsa - @kusumoto_ton
Update/Apply service in swarm clusterdocker service update nginx
Mr.Weerayut Hongsa - @kusumoto_ton
Update/Apply service in swarm clusterdocker service update nginx
Service name
Mr.Weerayut Hongsa - @kusumoto_ton
Update/Apply service in swarm clusterdocker service update nginx
Mr.Weerayut Hongsa - @kusumoto_ton
Delete service in swarm clusterdocker service rm nginx
Mr.Weerayut Hongsa - @kusumoto_ton
Delete service in swarm clusterdocker service rm nginx
Service name
Mr.Weerayut Hongsa - @kusumoto_ton
Delete service in swarm clusterdocker service rm nginx
Mr.Weerayut Hongsa - @kusumoto_ton
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
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
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
Delete stack in swarm clusterdocker stack rm my_stack
Mr.Weerayut Hongsa - @kusumoto_ton
Delete stack in swarm clusterdocker stack rm my_stack
Stack name
Mr.Weerayut Hongsa - @kusumoto_ton
Delete stack in swarm clusterdocker stack rm my_stack
Mr.Weerayut Hongsa - @kusumoto_ton
If you want to create your #dockerimage.
Mr.Weerayut Hongsa - @kusumoto_ton
but need to customize image via script.
Mr.Weerayut Hongsa - @kusumoto_ton
We’re recommend “Dockerfile”
Mr.Weerayut Hongsa - @kusumoto_ton
Format of the Dockerfile
# CommentINSTRUCTION arguments
Mr.Weerayut Hongsa - @kusumoto_ton
Example Dockerfile
FROM scratchCOPY hello /CMD ["/hello"]
Mr.Weerayut Hongsa - @kusumoto_ton
Example Dockerfile
FROM scratchCOPY hello /CMD ["/hello"]
FROM microsoft/nanoserverCOPY hello.txt C:CMD ["cmd", "/C", "type C:\\hello.txt"]
Mr.Weerayut Hongsa - @kusumoto_ton
Dockerfile Instruction • FROM • RUN• CMD• EXPOSE• ENV• ADD• COPY• ENTRYPOINT• VOLUME• USER• WORKDIR• ARG
Mr.Weerayut Hongsa - @kusumoto_ton
.dockerignore file• Defined filename or path ignore in docker image.• .dockerignore is same .gitignore
Mr.Weerayut Hongsa - @kusumoto_ton
Build image from Dockerfiledocker build -t kusumoto/tutu-bigo-tofblive .
Mr.Weerayut Hongsa - @kusumoto_ton
Build image from Dockerfiledocker build -t kusumoto/tutu-bigo-tofblive .
Image Name Path Dockerfileparameter
Mr.Weerayut Hongsa - @kusumoto_ton
Build image from Dockerfiledocker build -t kusumoto/tutu-bigo-tofblive .
Mr.Weerayut Hongsa - @kusumoto_ton