Slide 1

Slide 1 text

Docker x PHP How to deploy PHP projects with docker. PHPConf 2014

Slide 2

Slide 2 text

Who am I ? • Ruoshi Lin (@fntsrlike)! • 深藏若虛! • 2.5 Y PHPer ! • fntsr.tw Photo by

Slide 3

Slide 3 text

What will I Talk today? Application! 20% Use! 35% Concept! 35% Story! 10%

Slide 4

Slide 4 text

What story I wanna! talk before speech ?

Slide 5

Slide 5 text

The situation we! deploy PHP Projects! that we feel HURT HURT

Slide 6

Slide 6 text

PHP Version Requirement Laravel Symfony CodeIgniter Phalcon Yii Wordpress Drupal 7 Drupal 8 Drupal 6 Joomla MediaWiki DokuWiki

Slide 7

Slide 7 text

Laravel Symfony CodeIgniter Phalcon Yii Wordpress Drupal 7 Drupal 8 Drupal 6 Joomla MediaWiki DokuWiki There are so many! PHP Projects… PHP Version Requirement

Slide 8

Slide 8 text

Laravel 5.4+ Symfony 5.3.3+ CodeIgniter 5.1.6+ Phalcon 5.3+! Yii 5.1+ Wordpress 5.2.4+ Drupal-7 5.2.5+ Drupal-8 5.4+ Drupal-6 5.2.x Joomla! 5.4+ MediaWiki 5.3.2+ DokuWiki 5.2 But version ! requirement ! are different!? PHP Version Requirement

Slide 9

Slide 9 text

` Laravel 5.4+ Symfony 5.3.3+ CodeIgniter 5.1.6+ Phalcon 5.3+! Yii 5.1+ Wordpress 5.2.4+ Drupal-7 5.2.5+ Drupal-8 5.4+ Drupal-6 5.2.x Joomla! 5.4+ MediaWiki 5.3.2+ DokuWiki 5.2 WHICH PHP VERSION ! SHOULD I INSTALLED ?

Slide 10

Slide 10 text

Multifarious Extension

Slide 11

Slide 11 text

Multifarious Extension apxs2, bcmath, bz2, calendar, cgi, cli, ctype, dba, debug, 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, tokenizer, xml_all, xmlrpc, zip, zlib

Slide 12

Slide 12 text

Multifarious Extension apxs2, bcmath, bz2, calendar, cgi, cli, ctype, dba, debug, 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, tokenizer, xml_all, xmlrpc, zip, zlib PECL? ! Recompiled?

Slide 13

Slide 13 text

One Server Multi Projects Server App 1 PHP MySQL etc… App 2 PHP MySQL etc… App n PHP, DB, etc… ……

Slide 14

Slide 14 text

One Server Multi Projects Server App 1 PHP 5.3.2, MySQL 5.0.2, etc… App 2 PHP 5.4, MySQL 5.0.15, etc… App n PHP 5.4, MariaDB, etc… …… BUT DIFFERENT REQUIRMENT

Slide 15

Slide 15 text

某某專案需要更⾼高的PHP版本,我今天要把 伺服器的PHP版本升級喲~

Slide 16

Slide 16 text

某某專案需要更⾼高的PHP版本,我今天要把 伺服器的PHP版本升級喲~

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

How To Solve Problems?

Slide 19

Slide 19 text

PHPBrew +

Slide 20

Slide 20 text

PHPBrew + @c9s

Slide 21

Slide 21 text

PHPBrew + Almost enough. @c9s

Slide 22

Slide 22 text

PHPBrew + Almost enough. But may we had ! encapsulation and portability ? @c9s

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

That's awesome!

Slide 25

Slide 25 text

That's awesome! But may it be more lightweight?

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Maybe you can try to use DOCKER!

Slide 28

Slide 28 text

How docker can help us?

Slide 29

Slide 29 text

How docker can help us? Built specify environment for target project.

Slide 30

Slide 30 text

How docker can help us? Built specify environment for target project.! Isolate every project space.

Slide 31

Slide 31 text

How docker can help us? Built specify environment for target project.! Isolate every project space.! Package it and be portable.

Slide 32

Slide 32 text

How docker can help us? Built specify environment for target project.! Isolate every project space.! Package it and be portable.! Deploy lightweight and fast.

Slide 33

Slide 33 text

WHAT IS DOCKER ?

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

This is Dock!

Slide 36

Slide 36 text

DOCK

Slide 37

Slide 37 text

DOCK -ER

Slide 38

Slide 38 text

? DOCK -ER

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

What is it? Build, Ship and Run Any App, Anywhere Docker - An open platform for distributed applications for developers and sysadmins. -docker.io

Slide 42

Slide 42 text

LXC ! Not VM ! Encapsulation! Portability ! Lightweight What is it?

Slide 43

Slide 43 text

LXC Linux Container is a userspace interface ! for the Linux kernel containment features.

Slide 44

Slide 44 text

LXC Linux Container is a userspace interface ! for the Linux kernel containment features. What?

Slide 45

Slide 45 text

LXC ! Kernel 
 namespaces! PID, mount, user, network, UTS, IPC!

Slide 46

Slide 46 text

LXC ! Kernel 
 namespaces! Cgroups PID, mount, user, network, UTS, IPC! cpu, memory, disk I/O!

Slide 47

Slide 47 text

LXC ! Kernel 
 namespaces! Cgroups Chroot PID, mount, user, network, UTS, IPC! cpu, memory, disk I/O! File system!

Slide 48

Slide 48 text

What different between VM and Docker

Slide 49

Slide 49 text

Virtual Machine Server Host OS Hypervisor Guest OS /usr/bin, /usr/lib, … App Guest OS /usr/bin, /usr/lib, … App 2 Guest OS /usr/bin, /usr/lib, … App'

Slide 50

Slide 50 text

Virtual Machine Server Host OS Hypervisor Guest OS /usr/bin, /usr/lib, … App Guest OS /usr/bin, /usr/lib, … App 2 Guest OS /usr/bin, /usr/lib, … App' VM1 VM2 VM3

Slide 51

Slide 51 text

Virtual Machine Server Host OS Hypervisor Guest OS PHP 5.2 PHP App Guest OS PHP 5.4 PHP App2 Guest OS PHP 5.3 PHP App' VM1 VM2 VM3

Slide 52

Slide 52 text

Docker Server Host OS /bin, /lib PHP ! App3 Docker /bin, /lib PHP ! App4 /bin, /lib PHP ! App PHP ! App`

Slide 53

Slide 53 text

Docker Server Host OS /bin, /lib PHP ! App3 Docker Docker container /bin, /lib PHP ! App4 /bin, /lib PHP ! App PHP ! App` /bin, /lib

Slide 54

Slide 54 text

Docker Server Host OS PHP 5.3 PHP ! App3 Docker Docker container PHP 5.4 PHP ! App4 PHP 5.2 PHP ! App PHP ! App` PHP 5.2

Slide 55

Slide 55 text

Docker Server Host OS PHP 5.3 PHP ! App3 Docker Docker container PHP 5.4 PHP ! App4 Shared FS with AUFS PHP 5.2 PHP ! App PHP ! App` PHP 5.2

Slide 56

Slide 56 text

Docker Container Kernel LXC AUFS Docker Base image (Ubuntu) Image (php) Image (apache) Container Base image (CentOS) Image (nginx) Container Container

Slide 57

Slide 57 text

Docker Container Kernel LXC AUFS Docker Base image (Ubuntu) Image (php) Image (apache) Container Base image (CentOS) Image (nginx) Container Container Parent ! Reference

Slide 58

Slide 58 text

We knew LXC,! but what is AUFS?

Slide 59

Slide 59 text

AUFS • Layered FS! • Share commonFS! • RO & RW! • Used to share between container

Slide 60

Slide 60 text

AUFS • Layered FS! • Share commonFS! • RO & RW! • Used to share between container Can't understand? Let's see the Picture!

Slide 61

Slide 61 text

AUFS Add Files A Add Files B Add Files C Delete Files B Add Files E Add Files D

Slide 62

Slide 62 text

AUFS Add Files A Add Files B Add Files C Delete Files B Add Files E Add Files D Layered FS

Slide 63

Slide 63 text

AUFS Add Files A Add Files B Add Files C Delete Files B Add Files E Add Files D Share commonFS

Slide 64

Slide 64 text

AUFS Base image Image Image Container Container Container

Slide 65

Slide 65 text

AUFS Base image Image Image Container Container Container ReadOnly ReadWrite

Slide 66

Slide 66 text

AUFS Base image Image Image Container Container Container Used to share between container

Slide 67

Slide 67 text

Images ReadOnly Layer! Don't change. ! Environments! Used to be container

Slide 68

Slide 68 text

Containers ReadWrite Layer! Running Process! Built with one or more images! Commit change to create image

Slide 69

Slide 69 text

Docker Container Kernel LXC AUFS Docker Base image (Ubuntu) Image (php) Image (apache) Container Base image (CentOS) Image (nginx) Container Container

Slide 70

Slide 70 text

Docker Container Kernel LXC AUFS Docker Base image (Ubuntu) Image (php) Image (apache) Container Base image (CentOS) Image (nginx) Container Container Read! Only

Slide 71

Slide 71 text

Docker Container Kernel LXC AUFS Docker Base image (Ubuntu) Image (php) Image (apache) Container Base image (CentOS) Image (nginx) Container Container Read! Only Writable

Slide 72

Slide 72 text

Relationship between image and container Image! (registry) Image! (registry)

Slide 73

Slide 73 text

Relationship between image and container Image! (local) PULL Image! (registry)

Slide 74

Slide 74 text

Relationship between image and container Image! (registry) Container RUN Image! (local) PULL

Slide 75

Slide 75 text

Relationship between image and container Image! (registry) Container RUN Container' CHANGE Image! (local) PULL

Slide 76

Slide 76 text

Relationship between image and container Image! (registry) Container RUN Container' CHANGE COMMIT Image! (local) PULL

Slide 77

Slide 77 text

Relationship between image and container Image! (registry) Container RUN Container' CHANGE COMMIT Image! (local) PULL PUSH Image! (registry)

Slide 78

Slide 78 text

Relationship between image and container Image! (registry) Container RUN Container' CHANGE COMMIT Image! (local) PULL PUSH

Slide 79

Slide 79 text

How to use docker ?

Slide 80

Slide 80 text

Requirements Linux kernel 3.8+! LXC! AUFS

Slide 81

Slide 81 text

Installation • Linux by package manager! • OS X, Windows by boot2docker! • Version 1.20

Slide 82

Slide 82 text

Installation • Linux by package manager! • OS X, Windows by boot2docker! • Version 1.20 1.3.0 released! 2014/10/16 Same day as my birthday >///<

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

Basic Command

Slide 85

Slide 85 text

Version $ docker version

Slide 86

Slide 86 text

Version $ docker version Client version: 1.3.0 Client API version: 1.15 Go version (client): go1.3.3 Git commit (client): c78088f OS/Arch (client): linux/amd64 Server version: 1.3.0 Server API version: 1.15 Go version (server): go1.3.3 Git commit (server): c78088f

Slide 87

Slide 87 text

Info $ docker info

Slide 88

Slide 88 text

Info $ docker info Containers: 4 Images: 71 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Dirs: 79 Execution Driver: native-0.2 Kernel Version: 3.13.0-36-generic Operating System: Ubuntu 14.04.1 LTS

Slide 89

Slide 89 text

Pull base image(s) $ docker pull ubuntu

Slide 90

Slide 90 text

Pull base image(s) $ docker pull ubuntu image name

Slide 91

Slide 91 text

Pull base image(s) $ docker pull ubuntu Pulling repository ubuntu 463ff6be4238: Download complete 9cbaf023786c: Download complete 2185fd50e2ca: Download complete a9561eb1b190: Download complete 3db9c44f4520: Download complete 195eb90b5349: Download complete c5881f11ded9: Download complete 511136ea3c5a: Download complete 500cae81e00f: Download complete 3ed75c4904e0: Download complete b8c495ea8a4e: Download complete 0f154c52e965: Download complete f180ea115597: Download complete bac448df371d: Download complete ……

Slide 92

Slide 92 text

List images $ docker images

Slide 93

Slide 93 text

List images $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.10 2185fd50e2ca 28 hours ago 237.2 MB ubuntu utopic 2185fd50e2ca 28 hours ago 237.2 MB ubuntu 14.04.1 9cbaf023786c 28 hours ago 192.8 MB ubuntu 14.04 9cbaf023786c 28 hours ago 192.8 MB ubuntu trusty 9cbaf023786c 28 hours ago 192.8 MB ubuntu latest 9cbaf023786c 28 hours ago 192.8 MB ubuntu precise a9561eb1b190 28 hours ago 120.2 MB ubuntu 12.04.5 a9561eb1b190 28 hours ago 120.2 MB ubuntu 12.04 a9561eb1b190 28 hours ago 120.2 MB ubuntu 12.10 c5881f11ded9 3 months ago 172.2 MB ubuntu quantal c5881f11ded9 3 months ago 172.2 MB ubuntu 13.04 463ff6be4238 3 months ago 169.4 MB ubuntu raring 463ff6be4238 3 months ago 169.4 MB ubuntu 13.10 195eb90b5349 3 months ago 184.7 MB ubuntu saucy 195eb90b5349 3 months ago 184.7 MB ……

Slide 94

Slide 94 text

Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world

Slide 95

Slide 95 text

Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name

Slide 96

Slide 96 text

Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name execute

Slide 97

Slide 97 text

Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name execute argument

Slide 98

Slide 98 text

Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 73ec6de5630b ubuntu:14.04 "/bin/echo 'hello, w 2 hours ago Exited (0) sad_engelbart image name execute argument

Slide 99

Slide 99 text

Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 73ec6de5630b ubuntu:14.04 "/bin/echo 'hello, w 2 hours ago Exited (0) sad_engelbart image name execute argument The container is finished, so we use -a

Slide 100

Slide 100 text

Run and list running container docker run ubuntu:latest /bin/sh -c \
 "while true; do echo hello, world; sleep 1; done;" hello, world hello, world …… $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8e46bc2bd17d ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

Slide 101

Slide 101 text

Run and list running container docker run ubuntu:latest /bin/sh -c \
 "while true; do echo hello, world; sleep 1; done;" hello, world hello, world …… $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8e46bc2bd17d ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow The container is running until we stop it

Slide 102

Slide 102 text

Run running container in deamon docker run -d ubuntu:latest /bin/sh -c \
 "while true; do echo hello, world; sleep 1; done;" 90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

Slide 103

Slide 103 text

Run running container in deamon docker run -d ubuntu:latest /bin/sh -c \
 "while true; do echo hello, world; sleep 1; done;" 90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

Slide 104

Slide 104 text

Run running container in deamon docker run -d ubuntu:latest /bin/sh -c \
 "while true; do echo hello, world; sleep 1; done;" 90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow We use container id to manage it

Slide 105

Slide 105 text

Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world ……

Slide 106

Slide 106 text

Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world …… Get logs

Slide 107

Slide 107 text

Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world …… Get logs Back to container console

Slide 108

Slide 108 text

Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world …… Get logs Back to container console 「CTRL-p CTRL-q」 to detach.!

Slide 109

Slide 109 text

Commit $ docker run -i -t php:5.6.1-apache /bin/bash! root@4441f36ebab1:/#
 You do some change …… Sets STDIN and open a PTY

Slide 110

Slide 110 text

Commit $ docker run -i -t php:5.6.1-apache /bin/bash! You do some change …… $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse

Slide 111

Slide 111 text

Commit $ docker run -i -t php:5.6.1-apache /bin/bash! You do some change …… $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse $ docker commit 6a495e871389 fntsr/first-image! 2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df

Slide 112

Slide 112 text

Commit $ docker run -i -t php:5.6.1-apache /bin/bash! You do some change …… $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse $ docker commit 6a495e871389 fntsr/first-image! 2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df /

Slide 113

Slide 113 text

Commit $ docker run -i -t php:5.6.1-apache /bin/bash! You do some change …… $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse $ docker commit 6a495e871389 fntsr/first-image! 2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df $ docker images! REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE fntsr/first-image latest 2006ba62eb65 22 minutes ago 803.6 MB

Slide 114

Slide 114 text

Expose Port docker run -d -p 80 nginx c63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS c63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp

Slide 115

Slide 115 text

Expose Port docker run -d -p 80 nginx c63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb -p ! $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS c63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp

Slide 116

Slide 116 text

Expose Port docker run -d -p 80 nginx c63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb -p ! $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS c63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp Expose 80 to 49153 (random) Expose to random port

Slide 117

Slide 117 text

docker run -d -p 10080:80 nginx afd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658 $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS afd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp Expose Port

Slide 118

Slide 118 text

docker run -d -p 10080:80 nginx afd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658 -p : $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS afd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp Expose Port

Slide 119

Slide 119 text

docker run -d -p 10080:80 nginx afd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658 -p : $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS afd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp Expose 80 to 10080 (assigned) Expose to assigned port Expose Port

Slide 120

Slide 120 text

docker run -d -p 127.0.0.1:10080:80 nginx 76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526 $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp Expose Port

Slide 121

Slide 121 text

docker run -d -p 127.0.0.1:10080:80 nginx 76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526 -p :: $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp Expose Port

Slide 122

Slide 122 text

docker run -d -p 127.0.0.1:10080:80 nginx 76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526 -p :: $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp Expose with host name Expose to host with hostname Expose Port

Slide 123

Slide 123 text

docker run -d -P nginx 2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048 $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED PORTS afd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp Expose Port

Slide 124

Slide 124 text

docker run -d -P nginx 2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048 -P $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED PORTS afd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp Expose Port

Slide 125

Slide 125 text

docker run -d -P nginx 2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048 -P $ docker ps -a! CONTAINER ID IMAGE COMMAND CREATED PORTS afd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp Expose all port of container ! with host random port 443 expose to 49154 (random) Expose Port

Slide 126

Slide 126 text

How could I back to running container and do another thing? • attach!

Slide 127

Slide 127 text

How could I back to running container and do another thing? • attach! It can only run one process.

Slide 128

Slide 128 text

How could I back to running container and do another thing? • attach! • exec It can only run one process.

Slide 129

Slide 129 text

How could I back to running container and do another thing? • attach! • exec It can only run one process. It's added on docker 1.3 (rock)

Slide 130

Slide 130 text

$ docker run nginx --name my-nginx -d nginx 4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" Alias

Slide 131

Slide 131 text

$ docker run nginx --name my-nginx -d nginx 4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" Alias $ docker exec -it nginx bin/bash CONTAINER ID IMAGE …… STATUS PORTS NAMES 4441f36ebab1 nginx:latest Up 4 seconds 443/tcp, 0.0.0.0:80->80/tcp my-nginx

Slide 132

Slide 132 text

$ docker run nginx --name my-nginx -d nginx 4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" $ docker exec -it my-nginx bin/bash root@4441f36ebab1:/# Alias $ docker ps CONTAINER ID IMAGE …… STATUS PORTS NAMES 4441f36ebab1 nginx:latest Up 4 seconds 443/tcp, 0.0.0.0:80->80/tcp my-nginx

Slide 133

Slide 133 text

Linking We don't have enough time… Let's see picture again! XD

Slide 134

Slide 134 text

Linking PHP+Nginx! Container Host MySQL! Container Port Port

Slide 135

Slide 135 text

Linking PHP+Nginx! Container Host MySQL! Container Port Port Let's try to hack!

Slide 136

Slide 136 text

Linking PHP+Nginx! Container Host MySQL! Container Port Port 斷開鎖鏈!

Slide 137

Slide 137 text

Linking PHP+Nginx! Container Host MySQL! Container Port Link Port 移情別戀!(不對

Slide 138

Slide 138 text

Linking PHP+Nginx! Container Host MySQL! Container Port Link Oops! More Secure

Slide 139

Slide 139 text

Volume Picture, BJ4

Slide 140

Slide 140 text

volume directory Host /var/www/html …… …… Container

Slide 141

Slide 141 text

volume directory Host /var/www/html …… …… Container Isolation

Slide 142

Slide 142 text

volume directory Host /var/www/html …… …… Container How could we mount container's directory to host?

Slide 143

Slide 143 text

volume directory Host /var/www/html …… …… Container Volume

Slide 144

Slide 144 text

volume directory Host /var/www/html …… …… Container Volume • Real time changes

Slide 145

Slide 145 text

volume directory Host /var/www/html …… …… Container Volume • Real time changes! • Exist until container destroyed!

Slide 146

Slide 146 text

volume directory Host /var/www/html …… …… Container Volume • Real time changes! • Exist until container destroyed! • Can set RO mode.

Slide 147

Slide 147 text

volume directory Host /var/www/html …… …… Container A /var/www/html …… Container B Share Volume between containers

Slide 148

Slide 148 text

volume directory Host /var/www/html …… …… Container A Volume /var/www/html …… Container B Share Volume between containers

Slide 149

Slide 149 text

volume directory Host /var/www/html …… …… Container A Volume /var/www/html …… Container B Share Volume between containers

Slide 150

Slide 150 text

Registry & Dockerfile

Slide 151

Slide 151 text

index.docker.io

Slide 152

Slide 152 text

registry = docker's github.

Slide 153

Slide 153 text

Official PHP Repo

Slide 154

Slide 154 text

Tutorial for using image

Slide 155

Slide 155 text

Dockerfile of image

Slide 156

Slide 156 text

Dockerfile • Automatically built images and deploy! • Automated Builds on Docker Hub! • Easy to share and customize config! !

Slide 157

Slide 157 text

We don't have time to talk how to write…but official document is completed.

Slide 158

Slide 158 text

Which patterns can we use?

Slide 159

Slide 159 text

Single app container PHP App Volume /var/www/html PHP 5.6 …… Nginx MySQL …… Port

Slide 160

Slide 160 text

Single app container PHP App Volume /var/www/html PHP 5.6 …… Nginx MySQL …… Port Not recommend use for production

Slide 161

Slide 161 text

Container Groups PHP App Volume /var/www/html …… Nginx /var/lib/mysql/ …… PHP 5.6 MySQL …… App Container DB Container Port Port Easy to manage

Slide 162

Slide 162 text

Separate containers …… PHP-apache FS php container …… MySQL FS MySQL container PHP App Volume …… Link Link Port …… Nginx FS nginx container volume Using in production

Slide 163

Slide 163 text

Data Only Container 8421917fbed8aa018ad3…. Volume /data …… /data …… …… DB-data Container DB Container volume from volume

Slide 164

Slide 164 text

How could I use docker to solve problem?

Slide 165

Slide 165 text

Multi PHP Projects Nginx HOST PHP project A /var/www/html …… PHP:5.6-apache ! Container PHP project B /var/www/html …… PHP:5.5-apache ! Container …… …… /var/www/html

Slide 166

Slide 166 text

Multi PHP Projects Nginx HOST PHP project A /var/www/html …… PHP:5.6-apache ! Container PHP project B /var/www/html …… PHP:5.5-apache ! Container …… …… /var/www/html volume

Slide 167

Slide 167 text

Multi PHP Projects Nginx HOST PHP project A /var/www/html …… PHP:5.6-apache ! Container /data …… DB Container PHP project B /var/www/html …… PHP:5.5-apache ! Container …… …… /var/www/html DB! Link volume

Slide 168

Slide 168 text

Multi PHP Projects Nginx HOST PHP project A /var/www/html …… PHP:5.6-apache ! Container /data …… DB Container PHP project B /var/www/html …… PHP:5.5-apache ! Container …… …… /var/www/html DB! Link volume Port

Slide 169

Slide 169 text

Thank you. Thanks my girlfriend especially.

Slide 170

Slide 170 text

Resource & Reference • Docker Documentation! • Digital Ocean! • boot2docker! • Ship it with Docker! by Xabier Larrakoetxea! • Docker.Taipei! • Flat UI Colors! • IcoMoon App

Slide 171

Slide 171 text

No content

Slide 172

Slide 172 text

Q & A