SlideShare une entreprise Scribd logo
1  sur  172
Télécharger pour lire hors ligne
Docker x PHP 
How to deploy PHP projects with docker. 
PHPConf 2014
Who am I ? 
• Ruoshi Lin (@fntsrlike)! 
• 深藏若虛! 
• 2.5 Y PHPer ! 
• fntsr.tw 
Photo by
What will I Talk today? 
Application! 
20% 
Use! 
35% 
Story! 
10% 
Concept! 
35%
What story I wanna! 
talk before speech ?
The situation we! 
deploy PHP Projects! 
that we feel HHUURRTT
PHP Version Requirement 
Laravel 
Symfony 
CodeIgniter Phalcon 
Yii 
Wordpress 
Joomla 
MediaWiki 
DokuWiki 
Drupal 6 Drupal 7 Drupal 8
PHP Version Requirement 
Laravel 
Symfony 
There are so many! 
PHP Projects… 
CodeIgniter Phalcon 
Yii 
Wordpress 
Joomla 
MediaWiki 
DokuWiki 
Drupal 6 Drupal 7 Drupal 8
PHP Version Requirement 
Symfony 5.3.3+ 
Laravel 5.4+ 
Yii 5.1+ 
But version ! 
requirement ! 
are different!? 
CodeIgniter 5.1.6+ Phalcon 5.3+! 
DokuWiki 5.2 
Wordpress 5.2.4+ 
Joomla! 5.4+ 
MediaWiki 5.3.2+ 
Drupal-7 Drupal-6 5.2.x 5.2.5+ Drupal-8 5.4+
WHICH PHP ` 
VERSION ! 
SHOULD I INSTALLED ? 
Symfony 5.3.3+ 
Laravel 5.4+ 
Yii 5.1+ 
CodeIgniter 5.1.6+ Phalcon 5.3+! 
DokuWiki 5.2 
Wordpress 5.2.4+ 
Joomla! 5.4+ 
MediaWiki 5.3.2+ 
Drupal-7 Drupal-6 5.2.x 5.2.5+ Drupal-8 5.4+
Multifarious Extension
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
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, 
PECL? ! 
Recompiled? 
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
One Server Multi Projects 
Server 
App 1 
PHP 
MySQL 
etc… 
App 2 
PHP 
MySQL 
etc… 
App n 
PHP, DB, 
etc… 
……
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
某某專案需要更⾼高的PHP版本,我今天要把 
伺服器的PHP版本升級喲~
某某專案需要更⾼高的PHP版本,我今天要把 
伺服器的PHP版本升級喲~
How to deploy PHP projects with docker
How To Solve 
Problems?
+ PHPBrew
+ PHPBrew 
@c9s
+ PHPBrew 
Almost enough. 
@c9s
+ PHPBrew 
Almost enough. 
But may we had ! 
encapsulation and portability ? 
@c9s
How to deploy PHP projects with docker
That's awesome!
That's awesome! 
But may it be more lightweight?
How to deploy PHP projects with docker
Maybe you can try to use 
DOCKER!
How docker can help us?
How docker can help us? 
Built specify environment for target project.
How docker can help us? 
Built specify environment for target project.! 
Isolate every project space.
How docker can help us? 
Built specify environment for target project.! 
Isolate every project space.! 
Package it and be portable.
How docker can help us? 
Built specify environment for target project.! 
Isolate every project space.! 
Package it and be portable.! 
Deploy lightweight and fast.
WHAT IS DOCKER ?
How to deploy PHP projects with docker
This is Dock!
DOCK
DOCK -ER
? 
DOCK -ER
How to deploy PHP projects with docker
How to deploy PHP projects with docker
What is it? 
Build, Ship and Run 
Any App, Anywhere 
Docker - An open platform for distributed 
applications for developers and sysadmins. 
-docker.io
LXC ! 
Not VM ! 
What is it? 
Encapsulation! 
Portability ! 
Lightweight
LXC 
Linux Container is a userspace interface ! 
for the Linux kernel containment features.
LXC 
Linux Container is a userspace interface ! 
for the Linux kernel containment features. 
What?
LXC 
! 
Kernel 
namespaces! 
PID, mount, 
user, network, 
UTS, IPC!
LXC 
! 
Kernel 
namespaces! 
Cgroups 
PID, mount, 
user, network, 
UTS, IPC! 
cpu, memory, 
disk I/O!
LXC 
! 
Kernel 
namespaces! 
Cgroups Chroot 
PID, mount, 
user, network, 
UTS, IPC! 
cpu, memory, 
disk I/O! 
File system!
What different between 
VM and Docker
Virtual Machine 
App' 
/usr/bin, /usr/lib, … 
Hypervisor 
Host OS 
Server 
App 
/usr/bin, /usr/lib, … 
Guest OS 
App 2 
/usr/bin, /usr/lib, … 
Guest OS 
Guest OS
Virtual Machine 
VM1 VM2 VM3 
App' 
/usr/bin, /usr/lib, … 
Hypervisor 
Host OS 
Server 
App 
/usr/bin, /usr/lib, … 
Guest OS 
App 2 
/usr/bin, /usr/lib, … 
Guest OS 
Guest OS
Virtual Machine 
VM1 VM2 VM3 
PHP App' 
PHP 5.3 
Hypervisor 
Host OS 
Server 
PHP App 
PHP 5.2 
Guest OS 
PHP App2 
PHP 5.4 
Guest OS 
Guest OS
Docker 
PHP ! 
App3 
/bin, /lib 
Host OS 
Server 
Docker 
PHP ! 
App4 
/bin, /lib 
PHP ! 
App 
PHP ! 
App` 
/bin, /lib
Docker 
PHP ! 
App3 
/bin, /lib 
Host OS 
Server 
Docker 
Docker container 
PHP ! 
App4 
/bin, /lib 
PHP ! 
App 
PHP ! 
App` 
/bin, /lib
Docker 
PHP ! 
App3 
PHP 5.3 
Host OS 
Server 
Docker 
Docker container 
PHP ! 
App4 
PHP 5.4 
PHP ! 
App 
PHP ! 
App` 
PHP 5.2
Docker 
PHP ! 
App3 
PHP 5.3 
Host OS 
Server 
Docker 
Docker container 
PHP ! 
App4 
PHP 5.4 
Shared FS with AUFS 
PHP ! 
App 
PHP ! 
App` 
PHP 5.2
Docker Container 
Container 
Image (apache) 
Base image (Ubuntu) 
Container Container 
Docker 
Image (nginx) 
LXC AUFS 
Kernel 
Image (php) 
Base image (CentOS)
Docker Container 
Container 
Image (apache) 
Parent ! Container Container 
Reference 
Base image (Ubuntu) 
Docker 
Image (nginx) 
LXC AUFS 
Kernel 
Image (php) 
Base image (CentOS)
We knew LXC,! 
but what is AUFS?
AUFS 
• Layered FS! 
• Share commonFS! 
• RO & RW! 
• Used to share between container
AUFS 
• Layered FS! 
• Share commonFS! 
• RO & RW! 
• Used to share between container 
Can't understand? Let's see the Picture!
AUFS 
Add Files C 
Add Files B 
Add Files A 
Delete Files B 
Add Files E 
Add Files D
AUFS 
Add Files C 
Add Files B 
Add Files A 
Delete Files B 
Add Files E 
Add Files D 
Layered FS
AUFS 
Add Files C 
Add Files B 
Add Files A 
Delete Files B 
Add Files E 
Add Files D 
Share commonFS
AUFS 
Image 
Image 
Base image 
Container 
Container 
Container
AUFS 
Image 
Image 
Base image 
Container 
Container 
Container 
ReadOnly 
ReadWrite
AUFS 
Used to share between container 
Image 
Image 
Base image 
Container 
Container 
Container
Images 
ReadOnly Layer! 
Don't change. ! 
Environments! 
Used to be container
Containers 
ReadWrite Layer! 
Running Process! 
Built with one or more images! 
Commit change to create image
Docker Container 
Container 
Image (apache) 
Base image (Ubuntu) 
Container Container 
Docker 
Image (nginx) 
LXC AUFS 
Kernel 
Image (php) 
Base image (CentOS)
Docker Container 
Container 
Image (apache) 
Base image (Ubuntu) 
Container Container 
Docker 
Image (nginx) 
LXC AUFS 
Kernel 
Image (php) 
Base image (CentOS) 
Read! 
Only
Docker Container 
Container 
Image (apache) 
Base image (Ubuntu) 
Container Container 
Docker 
Image (nginx) 
LXC AUFS 
Kernel 
Image (php) 
Base image (CentOS) 
Read! 
Only 
Writable
Relationship between 
image and container 
ImageImage! 
! 
(registry) 
(registry)
Relationship between 
image and container 
Image! 
(local) 
PULL 
Image! 
(registry)
Relationship between 
image and container 
Image! 
(registry) 
RUN 
Container 
Image! 
(local) 
PULL
Relationship between 
image and container 
Image! 
(registry) 
RUN 
Container 
Container' 
Image! 
(local) 
CHANGE 
PULL
Relationship between 
image and container 
Image! 
(registry) 
RUN 
Container 
Container' 
CHANGE 
COMMIT 
Image! 
(local) 
PULL
Relationship between 
image and container 
Image! 
(registry) 
RUN 
Container 
Container' 
CHANGE 
COMMIT 
Image! 
(local) 
PULL 
PUSH 
Image! 
(registry)
Relationship between 
image and container 
Image! 
(registry) 
RUN 
Container 
Container' 
CHANGE 
COMMIT 
Image! 
(local) 
PULL 
PUSH
How to use docker ?
Requirements 
Linux kernel 3.8+! 
LXC! 
AUFS
Installation 
• Linux by package manager! 
• OS X, Windows by boot2docker! 
• Version 1.20
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 >///<
How to deploy PHP projects with docker
Basic Command
Version 
$ docker version
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
Info 
$ docker info
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
Pull base image(s) 
$ docker pull ubuntu
Pull base image(s) 
$ docker pull ubuntu 
image name
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 
……
List images 
$ docker images
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 
……
Run and List container 
$ docker run ubuntu:trusty /bin/echo "hello, world" 
hello, world
Run and List container 
$ docker run ubuntu:trusty /bin/echo "hello, world" 
hello, world 
image name
Run and List container 
$ docker run ubuntu:trusty /bin/echo "hello, world" 
hello, world 
image name execute
Run and List container 
$ docker run ubuntu:trusty /bin/echo "hello, world" 
hello, world 
image name execute argument
Run and List container 
$ docker run ubuntu:trusty /bin/echo "hello, world" 
hello, world 
image name execute argument 
$ 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
Run and List container 
$ docker run ubuntu:trusty /bin/echo "hello, world" 
hello, world 
image name execute argument 
$ 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 
The container is finished, so we use -a
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
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 
…… 
The container is running until we stop it 
$ 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
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
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
Run running container in deamon 
docker run -d ubuntu:latest /bin/sh -c  
"while true; do echo hello, world; sleep 1; done;" 
90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb 
We use container id to manage it 
$ 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
Logs and Attach Container 
$ docker logs 90f0ca 
hello, world 
hello, world 
…… 
$ docker attach 90f0ca 
hello, world 
hello, world 
……
Logs and Attach Container 
$ docker logs 90f0ca 
hello, world 
hello, world 
…… 
$ docker attach 90f0ca 
hello, world 
hello, world 
…… 
Get logs
Logs and Attach Container 
$ docker logs 90f0ca 
hello, world 
hello, world 
…… 
$ docker attach 90f0ca 
hello, world 
hello, world 
…… 
Get logs 
Back to container console
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.!
Commit 
$ docker run -i -t php:5.6.1-apache /bin/bash! 
root@4441f36ebab1:/# 
You do some change …… 
Sets STDIN and open a PTY
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
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
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 
<username>/<image_name>
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
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
Expose Port 
-p <guest_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
Expose Port 
-p <guest_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 
Expose 80 to 49153 
(random) 
Expose to random port
Expose Port 
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 
-p <host_port>:<guest_port> 
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 
-p <host_port>:<guest_port> 
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 80 to 10080 
(assigned) 
Expose to assigned port
Expose Port 
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 
-p <hostname>:<host_port>:<guest_port> 
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 
Expose to host with hostname 
-p <hostname>:<host_port>:<guest_port> 
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 with host name
Expose Port 
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 
-P 
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 
-P 
Expose all port of container ! 
with host random port 
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 
443 expose to 49154 
(random)
How could I back to running 
container and do another thing? 
• attach!
How could I back to running 
container and do another thing? 
• attach! It can only run one process.
How could I back to running 
container and do another thing? 
• attach! 
• exec 
It can only run one process.
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)
Alias 
$ docker run nginx --name my-nginx -d nginx 
4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"
Alias 
$ docker run nginx --name my-nginx -d nginx 
4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" 
$ 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
$ docker run nginx --name my-nginx -d nginx 
4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" 
$ docker exec -it my-nginx bin/bash 
root@4441f36ebab1:/# 
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
Linking 
We don't have enough time… 
Let's see picture again! XD
Linking 
PHP+Nginx! 
Container 
Host 
MySQL! 
Container 
Port 
Port
Linking 
PHP+Nginx! 
Container 
Host 
MySQL! 
Container 
Port 
Port 
Let's try to hack!
Linking 
PHP+Nginx! 
Container 
Host 
MySQL! 
Container 
Port 
Port 
斷開鎖鏈!
Linking 
PHP+Nginx! 
Container 
Host 
MySQL! 
Container 
Port 
Link 
Port 
移情別戀!(不對
Linking 
PHP+Nginx! 
Container 
Host 
MySQL! 
Container 
Port 
Link 
Oops! 
More Secure
Volume 
Picture, BJ4
Host 
volume directory 
/var/www/html 
…… 
…… 
Container
Host 
volume directory 
/var/www/html 
…… 
…… 
Container 
Isolation
Host 
volume directory 
/var/www/html 
…… 
…… 
Container 
How could we mount 
container's directory to host?
Host 
volume directory 
/var/www/html 
…… 
…… 
Volume Container
Host 
volume directory 
/var/www/html 
…… 
…… 
Volume Container 
• Real time changes
Host 
volume directory 
/var/www/html 
…… 
…… 
Volume Container 
• Real time changes! 
• Exist until container destroyed!
Host 
volume directory 
/var/www/html 
…… 
…… 
Volume Container 
• Real time changes! 
• Exist until container destroyed! 
• Can set RO mode.
Share Volume between containers 
Host 
volume directory 
/var/www/html 
…… 
…… 
Container A 
/var/www/html 
…… 
Container B
Share Volume between containers 
Host 
volume directory 
/var/www/html 
…… 
…… 
Container A Volume 
/var/www/html 
…… 
Container B
Share Volume between containers 
Host 
volume directory 
/var/www/html 
…… 
…… 
Container A Volume 
/var/www/html 
…… 
Container B
Registry & Dockerfile
index.docker.io
registry = docker's github.
Official PHP Repo
Tutorial for using image
Dockerfile of image
Dockerfile 
• Automatically built images and deploy! 
• Automated Builds on Docker Hub! 
• Easy to share and customize config! 
!
We don't have time to talk how to write…but official 
document is completed.
Which patterns can 
we use?
Single app container 
Volume 
PHP App 
/var/www/html PHP 5.6 
…… Nginx 
MySQL 
…… 
Port
Single app container 
Volume 
PHP App 
/var/www/html PHP 5.6 
…… Nginx 
MySQL 
…… 
Port 
Not recommend use for production
Container Groups 
Volume /var/www/html 
PHP App 
…… Nginx 
/var/lib/mysql/ 
…… 
PHP 5.6 
MySQL 
…… 
App Container 
DB Container 
Port 
Port 
Easy to manage
Separate containers 
FS nginx container 
FS 
php container 
…… PHP-apache 
FS MySQL container 
…… MySQL 
Volume 
PHP App 
…… 
Link 
Link 
Port 
…… Nginx 
volume 
Using in production
Data Only Container 
Volume /data 
8421917fbed8aa018ad3…. 
…… 
/data 
…… 
…… 
DB-data Container 
volume from 
DB Container 
volume
How could I use docker 
to solve problem?
Multi PHP Projects 
HOST 
Nginx 
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 ……
Multi PHP Projects 
HOST 
Nginx 
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
Multi PHP Projects 
HOST 
Nginx 
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
Multi PHP Projects 
HOST 
Nginx 
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
Thank you. 
Thanks my girlfriend especially.
Resource & Reference 
• Docker Documentation! 
• Digital Ocean! 
• boot2docker! 
• Ship it with Docker! by Xabier Larrakoetxea! 
• Docker.Taipei! 
• Flat UI Colors! 
• IcoMoon App
How to deploy PHP projects with docker
Q & A

Contenu connexe

Tendances

Ch1-Software Engineering 9
Ch1-Software Engineering 9Ch1-Software Engineering 9
Ch1-Software Engineering 9Ian Sommerville
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven DesignDavid Berliner
 
status of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Event
status of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Eventstatus of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Event
status of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual EventBernardo A. Delicado
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introductionwojtek_s
 
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개CURVC Corp
 
Making Decisions - From Software Architecture Theory to Practice
Making Decisions - From Software Architecture Theory to PracticeMaking Decisions - From Software Architecture Theory to Practice
Making Decisions - From Software Architecture Theory to PracticeParis Avgeriou
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices ArchitectureJoshua Costa
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
Quality software management
Quality software managementQuality software management
Quality software managementArun Kumar
 
Quarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesQuarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesRed Hat Developers
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven DesignNicolò Pignatelli
 
Hexagonal Architecture
Hexagonal ArchitectureHexagonal Architecture
Hexagonal ArchitectureMarcelo Cure
 
Programação Orientada a Aspectos
Programação Orientada a AspectosProgramação Orientada a Aspectos
Programação Orientada a AspectosRicardo Terra
 
Embracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with FlywayEmbracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with FlywayRed Gate Software
 
Introduction To Open Source Licensing
Introduction To Open Source LicensingIntroduction To Open Source Licensing
Introduction To Open Source LicensingMark Radcliffe
 

Tendances (20)

Ch1-Software Engineering 9
Ch1-Software Engineering 9Ch1-Software Engineering 9
Ch1-Software Engineering 9
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven Design
 
status of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Event
status of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Eventstatus of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Event
status of INCOSE Systems Engineering Handbook 5th Edition - AISE Annual Event
 
Devops
DevopsDevops
Devops
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
 
Making Decisions - From Software Architecture Theory to Practice
Making Decisions - From Software Architecture Theory to PracticeMaking Decisions - From Software Architecture Theory to Practice
Making Decisions - From Software Architecture Theory to Practice
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Quality software management
Quality software managementQuality software management
Quality software management
 
Quarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesQuarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniques
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
 
Hexagonal Architecture
Hexagonal ArchitectureHexagonal Architecture
Hexagonal Architecture
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Programação Orientada a Aspectos
Programação Orientada a AspectosProgramação Orientada a Aspectos
Programação Orientada a Aspectos
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Embracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with FlywayEmbracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with Flyway
 
Introduction To Open Source Licensing
Introduction To Open Source LicensingIntroduction To Open Source Licensing
Introduction To Open Source Licensing
 
Work shop eventstorming
Work shop  eventstormingWork shop  eventstorming
Work shop eventstorming
 

Similaire à How to deploy PHP projects with docker

Docker module 1
Docker module 1Docker module 1
Docker module 1Liang Bo
 
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, OrchestrationThe Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, OrchestrationErica Windisch
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with DockerPatrick Mizer
 
Docker introduction
Docker introductionDocker introduction
Docker introductionPhuc Nguyen
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Henry Schreiner
 
CoreOS @ gluecon 2015
CoreOS @ gluecon 2015CoreOS @ gluecon 2015
CoreOS @ gluecon 2015ifup
 
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudPHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudSalesforce Developers
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Arun prasath
 
Docker Multi-arch All The Things
Docker Multi-arch All The ThingsDocker Multi-arch All The Things
Docker Multi-arch All The ThingsDocker, Inc.
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer ToolboxPablo Godel
 
Tribal Nova Docker feedback
Tribal Nova Docker feedbackTribal Nova Docker feedback
Tribal Nova Docker feedbackNicolas Degardin
 
PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...
PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...
PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...Yusuf Hadiwinata Sutandar
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014Carlo Bonamico
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...Codemotion
 
Apt get no more let Vagrant, Puppet and Docker take the stage
Apt get no more let Vagrant, Puppet and Docker take the stageApt get no more let Vagrant, Puppet and Docker take the stage
Apt get no more let Vagrant, Puppet and Docker take the stageAlessandro Cinelli (cirpo)
 
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideRapidValue
 

Similaire à How to deploy PHP projects with docker (20)

Docker module 1
Docker module 1Docker module 1
Docker module 1
 
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, OrchestrationThe Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with Docker
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
CoreOS @ gluecon 2015
CoreOS @ gluecon 2015CoreOS @ gluecon 2015
CoreOS @ gluecon 2015
 
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudPHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the Cloud
 
Core OS
Core OSCore OS
Core OS
 
Docker-v3.pdf
Docker-v3.pdfDocker-v3.pdf
Docker-v3.pdf
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
Docker Multi-arch All The Things
Docker Multi-arch All The ThingsDocker Multi-arch All The Things
Docker Multi-arch All The Things
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Tribal Nova Docker feedback
Tribal Nova Docker feedbackTribal Nova Docker feedback
Tribal Nova Docker feedback
 
PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...
PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...
PHPIDOL#80: Kubernetes 101 for PHP Developer. Yusuf Hadiwinata - VP Operation...
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
 
Apt get no more let Vagrant, Puppet and Docker take the stage
Apt get no more let Vagrant, Puppet and Docker take the stageApt get no more let Vagrant, Puppet and Docker take the stage
Apt get no more let Vagrant, Puppet and Docker take the stage
 
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
 

Dernier

9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 

Dernier (20)

9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 

How to deploy PHP projects with docker

  • 1. Docker x PHP How to deploy PHP projects with docker. PHPConf 2014
  • 2. Who am I ? • Ruoshi Lin (@fntsrlike)! • 深藏若虛! • 2.5 Y PHPer ! • fntsr.tw Photo by
  • 3. What will I Talk today? Application! 20% Use! 35% Story! 10% Concept! 35%
  • 4. What story I wanna! talk before speech ?
  • 5. The situation we! deploy PHP Projects! that we feel HHUURRTT
  • 6. PHP Version Requirement Laravel Symfony CodeIgniter Phalcon Yii Wordpress Joomla MediaWiki DokuWiki Drupal 6 Drupal 7 Drupal 8
  • 7. PHP Version Requirement Laravel Symfony There are so many! PHP Projects… CodeIgniter Phalcon Yii Wordpress Joomla MediaWiki DokuWiki Drupal 6 Drupal 7 Drupal 8
  • 8. PHP Version Requirement Symfony 5.3.3+ Laravel 5.4+ Yii 5.1+ But version ! requirement ! are different!? CodeIgniter 5.1.6+ Phalcon 5.3+! DokuWiki 5.2 Wordpress 5.2.4+ Joomla! 5.4+ MediaWiki 5.3.2+ Drupal-7 Drupal-6 5.2.x 5.2.5+ Drupal-8 5.4+
  • 9. WHICH PHP ` VERSION ! SHOULD I INSTALLED ? Symfony 5.3.3+ Laravel 5.4+ Yii 5.1+ CodeIgniter 5.1.6+ Phalcon 5.3+! DokuWiki 5.2 Wordpress 5.2.4+ Joomla! 5.4+ MediaWiki 5.3.2+ Drupal-7 Drupal-6 5.2.x 5.2.5+ Drupal-8 5.4+
  • 11. 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
  • 12. 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, PECL? ! Recompiled? 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
  • 13. One Server Multi Projects Server App 1 PHP MySQL etc… App 2 PHP MySQL etc… App n PHP, DB, etc… ……
  • 14. 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
  • 18. How To Solve Problems?
  • 21. + PHPBrew Almost enough. @c9s
  • 22. + PHPBrew Almost enough. But may we had ! encapsulation and portability ? @c9s
  • 25. That's awesome! But may it be more lightweight?
  • 27. Maybe you can try to use DOCKER!
  • 28. How docker can help us?
  • 29. How docker can help us? Built specify environment for target project.
  • 30. How docker can help us? Built specify environment for target project.! Isolate every project space.
  • 31. How docker can help us? Built specify environment for target project.! Isolate every project space.! Package it and be portable.
  • 32. How docker can help us? Built specify environment for target project.! Isolate every project space.! Package it and be portable.! Deploy lightweight and fast.
  • 36. DOCK
  • 41. What is it? Build, Ship and Run Any App, Anywhere Docker - An open platform for distributed applications for developers and sysadmins. -docker.io
  • 42. LXC ! Not VM ! What is it? Encapsulation! Portability ! Lightweight
  • 43. LXC Linux Container is a userspace interface ! for the Linux kernel containment features.
  • 44. LXC Linux Container is a userspace interface ! for the Linux kernel containment features. What?
  • 45. LXC ! Kernel namespaces! PID, mount, user, network, UTS, IPC!
  • 46. LXC ! Kernel namespaces! Cgroups PID, mount, user, network, UTS, IPC! cpu, memory, disk I/O!
  • 47. LXC ! Kernel namespaces! Cgroups Chroot PID, mount, user, network, UTS, IPC! cpu, memory, disk I/O! File system!
  • 48. What different between VM and Docker
  • 49. Virtual Machine App' /usr/bin, /usr/lib, … Hypervisor Host OS Server App /usr/bin, /usr/lib, … Guest OS App 2 /usr/bin, /usr/lib, … Guest OS Guest OS
  • 50. Virtual Machine VM1 VM2 VM3 App' /usr/bin, /usr/lib, … Hypervisor Host OS Server App /usr/bin, /usr/lib, … Guest OS App 2 /usr/bin, /usr/lib, … Guest OS Guest OS
  • 51. Virtual Machine VM1 VM2 VM3 PHP App' PHP 5.3 Hypervisor Host OS Server PHP App PHP 5.2 Guest OS PHP App2 PHP 5.4 Guest OS Guest OS
  • 52. Docker PHP ! App3 /bin, /lib Host OS Server Docker PHP ! App4 /bin, /lib PHP ! App PHP ! App` /bin, /lib
  • 53. Docker PHP ! App3 /bin, /lib Host OS Server Docker Docker container PHP ! App4 /bin, /lib PHP ! App PHP ! App` /bin, /lib
  • 54. Docker PHP ! App3 PHP 5.3 Host OS Server Docker Docker container PHP ! App4 PHP 5.4 PHP ! App PHP ! App` PHP 5.2
  • 55. Docker PHP ! App3 PHP 5.3 Host OS Server Docker Docker container PHP ! App4 PHP 5.4 Shared FS with AUFS PHP ! App PHP ! App` PHP 5.2
  • 56. Docker Container Container Image (apache) Base image (Ubuntu) Container Container Docker Image (nginx) LXC AUFS Kernel Image (php) Base image (CentOS)
  • 57. Docker Container Container Image (apache) Parent ! Container Container Reference Base image (Ubuntu) Docker Image (nginx) LXC AUFS Kernel Image (php) Base image (CentOS)
  • 58. We knew LXC,! but what is AUFS?
  • 59. AUFS • Layered FS! • Share commonFS! • RO & RW! • Used to share between container
  • 60. AUFS • Layered FS! • Share commonFS! • RO & RW! • Used to share between container Can't understand? Let's see the Picture!
  • 61. AUFS Add Files C Add Files B Add Files A Delete Files B Add Files E Add Files D
  • 62. AUFS Add Files C Add Files B Add Files A Delete Files B Add Files E Add Files D Layered FS
  • 63. AUFS Add Files C Add Files B Add Files A Delete Files B Add Files E Add Files D Share commonFS
  • 64. AUFS Image Image Base image Container Container Container
  • 65. AUFS Image Image Base image Container Container Container ReadOnly ReadWrite
  • 66. AUFS Used to share between container Image Image Base image Container Container Container
  • 67. Images ReadOnly Layer! Don't change. ! Environments! Used to be container
  • 68. Containers ReadWrite Layer! Running Process! Built with one or more images! Commit change to create image
  • 69. Docker Container Container Image (apache) Base image (Ubuntu) Container Container Docker Image (nginx) LXC AUFS Kernel Image (php) Base image (CentOS)
  • 70. Docker Container Container Image (apache) Base image (Ubuntu) Container Container Docker Image (nginx) LXC AUFS Kernel Image (php) Base image (CentOS) Read! Only
  • 71. Docker Container Container Image (apache) Base image (Ubuntu) Container Container Docker Image (nginx) LXC AUFS Kernel Image (php) Base image (CentOS) Read! Only Writable
  • 72. Relationship between image and container ImageImage! ! (registry) (registry)
  • 73. Relationship between image and container Image! (local) PULL Image! (registry)
  • 74. Relationship between image and container Image! (registry) RUN Container Image! (local) PULL
  • 75. Relationship between image and container Image! (registry) RUN Container Container' Image! (local) CHANGE PULL
  • 76. Relationship between image and container Image! (registry) RUN Container Container' CHANGE COMMIT Image! (local) PULL
  • 77. Relationship between image and container Image! (registry) RUN Container Container' CHANGE COMMIT Image! (local) PULL PUSH Image! (registry)
  • 78. Relationship between image and container Image! (registry) RUN Container Container' CHANGE COMMIT Image! (local) PULL PUSH
  • 79. How to use docker ?
  • 80. Requirements Linux kernel 3.8+! LXC! AUFS
  • 81. Installation • Linux by package manager! • OS X, Windows by boot2docker! • Version 1.20
  • 82. 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 >///<
  • 85. Version $ docker version
  • 86. 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
  • 88. 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
  • 89. Pull base image(s) $ docker pull ubuntu
  • 90. Pull base image(s) $ docker pull ubuntu image name
  • 91. 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 ……
  • 92. List images $ docker images
  • 93. 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 ……
  • 94. Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world
  • 95. Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name
  • 96. Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name execute
  • 97. Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name execute argument
  • 98. Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name execute argument $ 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
  • 99. Run and List container $ docker run ubuntu:trusty /bin/echo "hello, world" hello, world image name execute argument $ 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 The container is finished, so we use -a
  • 100. 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
  • 101. 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 …… The container is running until we stop it $ 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
  • 102. 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
  • 103. 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
  • 104. Run running container in deamon docker run -d ubuntu:latest /bin/sh -c "while true; do echo hello, world; sleep 1; done;" 90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb We use container id to manage it $ 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
  • 105. Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world ……
  • 106. Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world …… Get logs
  • 107. Logs and Attach Container $ docker logs 90f0ca hello, world hello, world …… $ docker attach 90f0ca hello, world hello, world …… Get logs Back to container console
  • 108. 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.!
  • 109. Commit $ docker run -i -t php:5.6.1-apache /bin/bash! root@4441f36ebab1:/# You do some change …… Sets STDIN and open a PTY
  • 110. 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
  • 111. 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
  • 112. 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 <username>/<image_name>
  • 113. 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
  • 114. 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
  • 115. Expose Port -p <guest_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
  • 116. Expose Port -p <guest_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 Expose 80 to 49153 (random) Expose to random port
  • 117. Expose Port 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
  • 118. Expose Port -p <host_port>:<guest_port> 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
  • 119. Expose Port -p <host_port>:<guest_port> 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 80 to 10080 (assigned) Expose to assigned port
  • 120. Expose Port 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
  • 121. Expose Port -p <hostname>:<host_port>:<guest_port> 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
  • 122. Expose Port Expose to host with hostname -p <hostname>:<host_port>:<guest_port> 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 with host name
  • 123. Expose Port 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
  • 124. Expose Port -P 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
  • 125. Expose Port -P Expose all port of container ! with host random port 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 443 expose to 49154 (random)
  • 126. How could I back to running container and do another thing? • attach!
  • 127. How could I back to running container and do another thing? • attach! It can only run one process.
  • 128. How could I back to running container and do another thing? • attach! • exec It can only run one process.
  • 129. 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)
  • 130. Alias $ docker run nginx --name my-nginx -d nginx 4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"
  • 131. Alias $ docker run nginx --name my-nginx -d nginx 4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" $ 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
  • 132. $ docker run nginx --name my-nginx -d nginx 4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d" $ docker exec -it my-nginx bin/bash root@4441f36ebab1:/# 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
  • 133. Linking We don't have enough time… Let's see picture again! XD
  • 134. Linking PHP+Nginx! Container Host MySQL! Container Port Port
  • 135. Linking PHP+Nginx! Container Host MySQL! Container Port Port Let's try to hack!
  • 136. Linking PHP+Nginx! Container Host MySQL! Container Port Port 斷開鎖鏈!
  • 137. Linking PHP+Nginx! Container Host MySQL! Container Port Link Port 移情別戀!(不對
  • 138. Linking PHP+Nginx! Container Host MySQL! Container Port Link Oops! More Secure
  • 140. Host volume directory /var/www/html …… …… Container
  • 141. Host volume directory /var/www/html …… …… Container Isolation
  • 142. Host volume directory /var/www/html …… …… Container How could we mount container's directory to host?
  • 143. Host volume directory /var/www/html …… …… Volume Container
  • 144. Host volume directory /var/www/html …… …… Volume Container • Real time changes
  • 145. Host volume directory /var/www/html …… …… Volume Container • Real time changes! • Exist until container destroyed!
  • 146. Host volume directory /var/www/html …… …… Volume Container • Real time changes! • Exist until container destroyed! • Can set RO mode.
  • 147. Share Volume between containers Host volume directory /var/www/html …… …… Container A /var/www/html …… Container B
  • 148. Share Volume between containers Host volume directory /var/www/html …… …… Container A Volume /var/www/html …… Container B
  • 149. Share Volume between containers Host volume directory /var/www/html …… …… Container A Volume /var/www/html …… Container B
  • 156. Dockerfile • Automatically built images and deploy! • Automated Builds on Docker Hub! • Easy to share and customize config! !
  • 157. We don't have time to talk how to write…but official document is completed.
  • 158. Which patterns can we use?
  • 159. Single app container Volume PHP App /var/www/html PHP 5.6 …… Nginx MySQL …… Port
  • 160. Single app container Volume PHP App /var/www/html PHP 5.6 …… Nginx MySQL …… Port Not recommend use for production
  • 161. Container Groups Volume /var/www/html PHP App …… Nginx /var/lib/mysql/ …… PHP 5.6 MySQL …… App Container DB Container Port Port Easy to manage
  • 162. Separate containers FS nginx container FS php container …… PHP-apache FS MySQL container …… MySQL Volume PHP App …… Link Link Port …… Nginx volume Using in production
  • 163. Data Only Container Volume /data 8421917fbed8aa018ad3…. …… /data …… …… DB-data Container volume from DB Container volume
  • 164. How could I use docker to solve problem?
  • 165. Multi PHP Projects HOST Nginx 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 ……
  • 166. Multi PHP Projects HOST Nginx 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
  • 167. Multi PHP Projects HOST Nginx 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
  • 168. Multi PHP Projects HOST Nginx 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
  • 169. Thank you. Thanks my girlfriend especially.
  • 170. Resource & Reference • Docker Documentation! • Digital Ocean! • boot2docker! • Ship it with Docker! by Xabier Larrakoetxea! • Docker.Taipei! • Flat UI Colors! • IcoMoon App
  • 172. Q & A