how to deploy php projects with docker

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

Upload: ruoshi-ling

Post on 29-Nov-2014

234 views

Category:

Technology


9 download

DESCRIPTION

PHPConf 2014 http://phpconf.tw/2014/

TRANSCRIPT

Page 1: How to deploy PHP projects with docker

Docker x PHPHow to deploy PHP projects with docker.

PHPConf 2014

Page 2: How to deploy PHP projects with docker

Who am I ?• Ruoshi Lin (@fntsrlike)!

• 深藏若虛!

• 2.5 Y PHPer !

• fntsr.tw

Photo by

Page 3: How to deploy PHP projects with docker

What will I Talk today?

Application!20%

Use!35%

Concept!35%

Story!10%

Page 4: How to deploy PHP projects with docker

What story I wanna!talk before speech ?

Page 5: How to deploy PHP projects with docker

The situation we!deploy PHP Projects!

that we feel HURTHURT

Page 6: How to deploy PHP projects with docker

PHP Version Requirement

Laravel

Symfony

CodeIgniter Phalcon

Yii

Wordpress

Drupal 7 Drupal 8Drupal 6

Joomla

MediaWiki

DokuWiki

Page 7: How to deploy PHP projects with docker

Laravel

Symfony

CodeIgniter Phalcon

Yii

Wordpress

Drupal 7 Drupal 8Drupal 6

Joomla

MediaWiki

DokuWiki

There are so many!PHP Projects…

PHP Version Requirement

Page 8: How to deploy PHP projects with docker

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

Page 9: How to deploy PHP projects with docker

`

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 ?

Page 10: How to deploy PHP projects with docker

Multifarious Extension

Page 11: How to deploy PHP projects with docker

Multifarious Extensionapxs2, 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

Page 12: How to deploy PHP projects with docker

Multifarious Extensionapxs2, 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?

Page 13: How to deploy PHP projects with docker

One Server Multi Projects

Server

App 1PHP

MySQL etc…

App 2PHP

MySQL etc…

App nPHP, DB,

etc………

Page 14: How to deploy PHP projects with docker

One Server Multi Projects

Server

App 1PHP 5.3.2,

MySQL 5.0.2, etc…

App 2PHP 5.4,

MySQL 5.0.15, etc…

App nPHP 5.4, MariaDB,

etc…

……

BUT DIFFERENT REQUIRMENT

Page 15: How to deploy PHP projects with docker

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

Page 16: How to deploy PHP projects with docker

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

Page 17: How to deploy PHP projects with docker
Page 18: How to deploy PHP projects with docker

How To Solve Problems?

Page 19: How to deploy PHP projects with docker

PHPBrew+

Page 20: How to deploy PHP projects with docker

PHPBrew+@c9s

Page 21: How to deploy PHP projects with docker

PHPBrew+

Almost enough.

@c9s

Page 22: How to deploy PHP projects with docker

PHPBrew+

Almost enough.

But may we had !encapsulation and portability ?

@c9s

Page 23: How to deploy PHP projects with docker
Page 24: How to deploy PHP projects with docker

That's awesome!

Page 25: How to deploy PHP projects with docker

That's awesome!

But may it be more lightweight?

Page 26: How to deploy PHP projects with docker
Page 27: How to deploy PHP projects with docker

Maybe you can try to use DOCKER!

Page 28: How to deploy PHP projects with docker

How docker can help us?

Page 29: How to deploy PHP projects with docker

How docker can help us?

Built specify environment for target project.

Page 30: How to deploy PHP projects with docker

How docker can help us?

Built specify environment for target project.!

Isolate every project space.

Page 31: How to deploy PHP projects with docker

How docker can help us?

Built specify environment for target project.!

Isolate every project space.!

Package it and be portable.

Page 32: How to deploy PHP projects with docker

How docker can help us?

Built specify environment for target project.!

Isolate every project space.!

Package it and be portable.!

Deploy lightweight and fast.

Page 33: How to deploy PHP projects with docker

WHAT IS DOCKER ?

Page 34: How to deploy PHP projects with docker
Page 35: How to deploy PHP projects with docker

This is Dock!

Page 36: How to deploy PHP projects with docker

DOCK

Page 37: How to deploy PHP projects with docker

DOCK -ER

Page 38: How to deploy PHP projects with docker

?DOCK -ER

Page 39: How to deploy PHP projects with docker
Page 40: How to deploy PHP projects with docker
Page 41: 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

Page 42: How to deploy PHP projects with docker

LXC !

Not VM !

Encapsulation!

Portability !

Lightweight

What is it?

Page 43: How to deploy PHP projects with docker

LXC

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

Page 44: How to deploy PHP projects with docker

LXC

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

What?

Page 45: How to deploy PHP projects with docker

LXC

!

Kernel namespaces!

PID, mount, user, network,

UTS, IPC!

Page 46: How to deploy PHP projects with docker

LXC

!

Kernel namespaces! Cgroups

PID, mount, user, network,

UTS, IPC!

cpu, memory, disk I/O!

Page 47: How to deploy PHP projects with docker

LXC

!

Kernel namespaces! Cgroups Chroot

PID, mount, user, network,

UTS, IPC!

cpu, memory, disk I/O! File system!

Page 48: How to deploy PHP projects with docker

What different between VM and Docker

Page 49: How to deploy PHP projects with docker

Virtual Machine

ServerHost OS

Hypervisor

Guest OS

/usr/bin, /usr/lib, …

App

Guest OS

/usr/bin, /usr/lib, …

App 2

Guest OS

/usr/bin, /usr/lib, …

App'

Page 50: How to deploy PHP projects with docker

Virtual Machine

ServerHost 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

Page 51: How to deploy PHP projects with docker

Virtual Machine

ServerHost 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

Page 52: How to deploy PHP projects with docker

Docker

ServerHost OS

/bin, /lib

PHP !App3

Docker

/bin, /lib

PHP !App4

/bin, /lib

PHP !App

PHP !App`

Page 53: How to deploy PHP projects with docker

Docker

ServerHost OS

/bin, /lib

PHP !App3

Docker

Docker container

/bin, /lib

PHP !App4

/bin, /lib

PHP !App

PHP !App`

/bin, /lib

Page 54: How to deploy PHP projects with docker

Docker

ServerHost OS

PHP 5.3

PHP !App3

Docker

Docker container

PHP 5.4

PHP !App4

PHP 5.2

PHP !App

PHP !App`

PHP 5.2

Page 55: How to deploy PHP projects with docker

Docker

ServerHost 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

Page 56: How to deploy PHP projects with docker

Docker Container

Kernel

LXC AUFS

Docker

Base image (Ubuntu)

Image (php)

Image (apache)

Container

Base image (CentOS)

Image (nginx)

Container Container

Page 57: How to deploy PHP projects with docker

Docker Container

Kernel

LXC AUFS

Docker

Base image (Ubuntu)

Image (php)

Image (apache)

Container

Base image (CentOS)

Image (nginx)

Container ContainerParent !Reference

Page 58: How to deploy PHP projects with docker

We knew LXC,!but what is AUFS?

Page 59: How to deploy PHP projects with docker

AUFS• Layered FS!

• Share commonFS!

• RO & RW!

• Used to share between container

Page 60: How to deploy PHP projects with docker

AUFS• Layered FS!

• Share commonFS!

• RO & RW!

• Used to share between container

Can't understand? Let's see the Picture!

Page 61: How to deploy PHP projects with docker

AUFS

Add Files A

Add Files B

Add Files C

Delete Files B

Add Files E

Add Files D

Page 62: How to deploy PHP projects with docker

AUFS

Add Files A

Add Files B

Add Files C

Delete Files B

Add Files E

Add Files D

Layered FS

Page 63: How to deploy PHP projects with docker

AUFS

Add Files A

Add Files B

Add Files C

Delete Files B

Add Files E

Add Files D

Share commonFS

Page 64: How to deploy PHP projects with docker

AUFS

Base image

Image

Image

Container

Container

Container

Page 65: How to deploy PHP projects with docker

AUFS

Base image

Image

Image

Container

Container

Container

ReadOnly

ReadWrite

Page 66: How to deploy PHP projects with docker

AUFS

Base image

Image

Image

Container

Container

Container

Used to share between container

Page 67: How to deploy PHP projects with docker

ImagesReadOnly Layer!

Don't change. !

Environments!

Used to be container

Page 68: How to deploy PHP projects with docker

ContainersReadWrite Layer!

Running Process!

Built with one or more images!

Commit change to create image

Page 69: How to deploy PHP projects with docker

Docker Container

Kernel

LXC AUFS

Docker

Base image (Ubuntu)

Image (php)

Image (apache)

Container

Base image (CentOS)

Image (nginx)

Container Container

Page 70: How to deploy PHP projects with docker

Docker Container

Kernel

LXC AUFS

Docker

Base image (Ubuntu)

Image (php)

Image (apache)

Container

Base image (CentOS)

Image (nginx)

Container Container

Read!Only

Page 71: How to deploy PHP projects with docker

Docker Container

Kernel

LXC AUFS

Docker

Base image (Ubuntu)

Image (php)

Image (apache)

Container

Base image (CentOS)

Image (nginx)

Container Container

Read!Only

Writable

Page 72: How to deploy PHP projects with docker

Relationship between image and container

Image!(registry)

Image!(registry)

Page 73: How to deploy PHP projects with docker

Relationship between image and container

Image!(local)

PULLImage!

(registry)

Page 74: How to deploy PHP projects with docker

Relationship between image and container

Image!(registry)

Container

RUN

Image!(local)

PULL

Page 75: How to deploy PHP projects with docker

Relationship between image and container

Image!(registry)

Container

RUN

Container'CHANGE

Image!(local)

PULL

Page 76: How to deploy PHP projects with docker

Relationship between image and container

Image!(registry)

Container

RUN

Container'CHANGE

COMMIT

Image!(local)

PULL

Page 77: How to deploy PHP projects with docker

Relationship between image and container

Image!(registry)

Container

RUN

Container'CHANGE

COMMIT

Image!(local)

PULL

PUSHImage!(registry)

Page 78: How to deploy PHP projects with docker

Relationship between image and container

Image!(registry)

Container

RUN

Container'CHANGE

COMMIT

Image!(local)

PULL

PUSH

Page 79: How to deploy PHP projects with docker

How to use docker ?

Page 80: How to deploy PHP projects with docker

Requirements

Linux kernel 3.8+!

LXC!

AUFS

Page 81: How to deploy PHP projects with docker

Installation • Linux by package manager!

• OS X, Windows by boot2docker!

• Version 1.20

Page 82: How to deploy PHP projects with docker

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 >///<

Page 83: How to deploy PHP projects with docker
Page 84: How to deploy PHP projects with docker

Basic Command

Page 85: How to deploy PHP projects with docker

Version

$ docker version

Page 86: How to deploy PHP projects with docker

Version

$ docker versionClient version: 1.3.0Client API version: 1.15Go version (client): go1.3.3Git commit (client): c78088fOS/Arch (client): linux/amd64Server version: 1.3.0Server API version: 1.15Go version (server): go1.3.3Git commit (server): c78088f

Page 87: How to deploy PHP projects with docker

Info

$ docker info

Page 88: How to deploy PHP projects with docker

Info

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

Page 89: How to deploy PHP projects with docker

Pull base image(s)

$ docker pull ubuntu

Page 90: How to deploy PHP projects with docker

Pull base image(s)

$ docker pull ubuntu

image name

Page 91: How to deploy PHP projects with docker

Pull base image(s)

$ docker pull ubuntuPulling repository ubuntu463ff6be4238: Download complete9cbaf023786c: Download complete2185fd50e2ca: Download completea9561eb1b190: Download complete3db9c44f4520: Download complete195eb90b5349: Download completec5881f11ded9: Download complete511136ea3c5a: Download complete500cae81e00f: Download complete3ed75c4904e0: Download completeb8c495ea8a4e: Download complete0f154c52e965: Download completef180ea115597: Download completebac448df371d: Download complete……

Page 92: How to deploy PHP projects with docker

List images$ docker images

Page 93: How to deploy PHP projects with docker

List images$ docker images

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

Page 94: How to deploy PHP projects with docker

Run and List container

$ docker run ubuntu:trusty /bin/echo "hello, world"hello, world

Page 95: How to deploy PHP projects with docker

Run and List container

$ docker run ubuntu:trusty /bin/echo "hello, world"hello, world

image name

Page 96: How to deploy PHP projects with docker

Run and List container

$ docker run ubuntu:trusty /bin/echo "hello, world"hello, world

image name execute

Page 97: How to deploy PHP projects with docker

Run and List container

$ docker run ubuntu:trusty /bin/echo "hello, world"hello, world

image name execute argument

Page 98: How to deploy PHP projects with docker

Run and List container

$ docker run ubuntu:trusty /bin/echo "hello, world"hello, world

$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES73ec6de5630b ubuntu:14.04 "/bin/echo 'hello, w 2 hours ago Exited (0) sad_engelbart

image name execute argument

Page 99: How to deploy PHP projects with docker

Run and List container

$ docker run ubuntu:trusty /bin/echo "hello, world"hello, world

$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES73ec6de5630b 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

Page 100: How to deploy PHP projects with docker

Run and list running container

docker run ubuntu:latest /bin/sh -c \"while true; do echo hello, world; sleep 1; done;"

hello, worldhello, world……

$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8e46bc2bd17d ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

Page 101: How to deploy PHP projects with docker

Run and list running container

docker run ubuntu:latest /bin/sh -c \"while true; do echo hello, world; sleep 1; done;"

hello, worldhello, world……

$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8e46bc2bd17d ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

The container is running until we stop it

Page 102: How to deploy PHP projects with docker

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 NAMES90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

Page 103: How to deploy PHP projects with docker

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 NAMES90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

Page 104: How to deploy PHP projects with docker

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 NAMES90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow

We use container id to manage it

Page 105: How to deploy PHP projects with docker

Logs and Attach Container

$ docker logs 90f0cahello, worldhello, world……

$ docker attach 90f0cahello, worldhello, world……

Page 106: How to deploy PHP projects with docker

Logs and Attach Container

$ docker logs 90f0cahello, worldhello, world……

$ docker attach 90f0cahello, worldhello, world……

Get logs

Page 107: How to deploy PHP projects with docker

Logs and Attach Container

$ docker logs 90f0cahello, worldhello, world……

$ docker attach 90f0cahello, worldhello, world……

Get logs

Back to container console

Page 108: How to deploy PHP projects with docker

Logs and Attach Container

$ docker logs 90f0cahello, worldhello, world……

$ docker attach 90f0cahello, worldhello, world……

Get logs

Back to container console

「CTRL-p CTRL-q」 to detach.!

Page 109: How to deploy PHP projects with docker

Commit$ docker run -i -t php:5.6.1-apache /bin/bash!

root@4441f36ebab1:/# You do some change ……

Sets STDIN and open a PTY

Page 110: How to deploy PHP projects with docker

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 NAMES6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse

Page 111: How to deploy PHP projects with docker

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 NAMES6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse

$ docker commit 6a495e871389 fntsr/first-image!2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df

Page 112: How to deploy PHP projects with docker

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 NAMES6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse

$ docker commit 6a495e871389 fntsr/first-image!2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df

<username>/<image_name>

Page 113: How to deploy PHP projects with docker

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 NAMES6a495e871389 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 SIZEfntsr/first-image latest 2006ba62eb65 22 minutes ago 803.6 MB

Page 114: How to deploy PHP projects with docker

Expose Port

docker run -d -p 80 nginxc63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTSc63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp

Page 115: How to deploy PHP projects with docker

Expose Port

docker run -d -p 80 nginxc63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb

-p <guest_port>!

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTSc63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp

Page 116: How to deploy PHP projects with docker

Expose Port

docker run -d -p 80 nginxc63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb

-p <guest_port>!

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTSc63fda2248d0 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

Page 117: How to deploy PHP projects with docker

docker run -d -p 10080:80 nginxafd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTSafd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp

Expose Port

Page 118: How to deploy PHP projects with docker

docker run -d -p 10080:80 nginxafd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658

-p <host_port>:<guest_port>

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTSafd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp

Expose Port

Page 119: How to deploy PHP projects with docker

docker run -d -p 10080:80 nginxafd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658

-p <host_port>:<guest_port>

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTSafd45d0f7d34 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

Page 120: How to deploy PHP projects with docker

docker run -d -p 127.0.0.1:10080:80 nginx76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp

Expose Port

Page 121: How to deploy PHP projects with docker

docker run -d -p 127.0.0.1:10080:80 nginx76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526

-p <hostname>:<host_port>:<guest_port>

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp

Expose Port

Page 122: How to deploy PHP projects with docker

docker run -d -p 127.0.0.1:10080:80 nginx76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526

-p <hostname>:<host_port>:<guest_port>

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS76d00613ccb3 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

Page 123: How to deploy PHP projects with docker

docker run -d -P nginx2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED PORTSafd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp

Expose Port

Page 124: How to deploy PHP projects with docker

docker run -d -P nginx2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048

-P

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED PORTSafd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp

Expose Port

Page 125: How to deploy PHP projects with docker

docker run -d -P nginx2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048

-P

$ docker ps -a!CONTAINER ID IMAGE COMMAND CREATED PORTSafd45d0f7d34 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

Page 126: How to deploy PHP projects with docker

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

• attach!

Page 127: How to deploy PHP projects with docker

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

• attach! It can only run one process.

Page 128: How to deploy PHP projects with docker

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

• attach!

• exec

It can only run one process.

Page 129: How to deploy PHP projects with docker

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)

Page 130: How to deploy PHP projects with docker

$ docker run nginx --name my-nginx -d nginx4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"

Alias

Page 131: How to deploy PHP projects with docker

$ docker run nginx --name my-nginx -d nginx4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"

Alias

$ docker exec -it nginx bin/bashCONTAINER ID IMAGE …… STATUS PORTS NAMES4441f36ebab1 nginx:latest Up 4 seconds 443/tcp, 0.0.0.0:80->80/tcp my-nginx

Page 132: How to deploy PHP projects with docker

$ docker run nginx --name my-nginx -d nginx4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"

$ docker exec -it my-nginx bin/bash

root@4441f36ebab1:/#

Alias

$ docker exec -it nginx bin/bashCONTAINER ID IMAGE …… STATUS PORTS NAMES4441f36ebab1 nginx:latest Up 4 seconds 443/tcp, 0.0.0.0:80->80/tcp my-nginx

Page 133: How to deploy PHP projects with docker

LinkingWe don't have enough time…

Let's see picture again! XD

Page 134: How to deploy PHP projects with docker

LinkingPHP+Nginx!Container

Host

MySQL!Container

Port

Port

Page 135: How to deploy PHP projects with docker

LinkingPHP+Nginx!Container

Host

MySQL!Container

Port

Port

Let's try to hack!

Page 136: How to deploy PHP projects with docker

LinkingPHP+Nginx!Container

Host

MySQL!Container

Port

Port

斷開鎖鏈!

Page 137: How to deploy PHP projects with docker

LinkingPHP+Nginx!Container

Host

MySQL!Container

Port

Link

Port

移情別戀!(不對

Page 138: How to deploy PHP projects with docker

LinkingPHP+Nginx!Container

Host

MySQL!Container

Port

Link

Oops! More Secure

Page 139: How to deploy PHP projects with docker

VolumePicture, BJ4

Page 140: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

Container

Page 141: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

Container

Isolation

Page 142: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

Container

How could we mount container's directory to host?

Page 143: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

ContainerVolume

Page 144: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

ContainerVolume

• Real time changes

Page 145: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

ContainerVolume

• Real time changes!• Exist until container destroyed!

Page 146: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

ContainerVolume

• Real time changes!• Exist until container destroyed!• Can set RO mode.

Page 147: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

Container A

/var/www/html

……

Container B

Share Volume between containers

Page 148: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

Container AVolume

/var/www/html

……

Container B

Share Volume between containers

Page 149: How to deploy PHP projects with docker

volume directory

Host /var/www/html

…………

Container AVolume

/var/www/html

……

Container B

Share Volume between containers

Page 150: How to deploy PHP projects with docker

Registry & Dockerfile

Page 151: How to deploy PHP projects with docker

index.docker.io

Page 152: How to deploy PHP projects with docker

registry = docker's github.

Page 153: How to deploy PHP projects with docker

Official PHP Repo

Page 154: How to deploy PHP projects with docker

Tutorial for using image

Page 155: How to deploy PHP projects with docker

Dockerfile of image

Page 156: How to deploy PHP projects with docker

Dockerfile• Automatically built images and deploy!

• Automated Builds on Docker Hub!

• Easy to share and customize config!

!

Page 157: How to deploy PHP projects with docker

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

Page 158: How to deploy PHP projects with docker

Which patterns can we use?

Page 159: How to deploy PHP projects with docker

Single app container

PHP App

Volume /var/www/html PHP 5.6

…… Nginx

MySQL……

Port

Page 160: How to deploy PHP projects with docker

Single app container

PHP App

Volume /var/www/html PHP 5.6

…… Nginx

MySQL……

Port

Not recommend use for production

Page 161: How to deploy PHP projects with docker

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

Page 162: How to deploy PHP projects with docker

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

Page 163: How to deploy PHP projects with docker

Data Only Container

8421917fbed8aa018ad3….

Volume /data

……

/data

……

……

DB-data Container

DB Container

volume from

volume

Page 164: How to deploy PHP projects with docker

How could I use docker to solve problem?

Page 165: How to deploy PHP projects with docker

Multi PHP ProjectsNginxHOST

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

Page 166: How to deploy PHP projects with docker

Multi PHP ProjectsNginxHOST

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

Page 167: How to deploy PHP projects with docker

Multi PHP ProjectsNginxHOST

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

Page 168: How to deploy PHP projects with docker

Multi PHP ProjectsNginxHOST

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

Page 169: How to deploy PHP projects with docker

Thank you.

Thanks my girlfriend especially.

Page 170: How to deploy PHP projects with docker

Resource & Reference• Docker Documentation!

• Digital Ocean!

• boot2docker!

• Ship it with Docker! by Xabier Larrakoetxea!

• Docker.Taipei!

• Flat UI Colors!

• IcoMoon App

Page 171: How to deploy PHP projects with docker
Page 172: How to deploy PHP projects with docker

Q & A