當專案漸趕,當遷移也不再那麼難 (ship your projects with docker ecosystem)

73
䡗⻩㬩䈙恶! 䡗捘䳜⅀⑮掄熝槄 嗆夼!獒goutsmjlf 1 PHPConf Taiwan 2015

Upload: ruoshi-ling

Post on 22-Jan-2018

2.167 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

1

PHPConf Taiwan 2015

Page 2: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

2

2015-11-01-a p45 VALUME -> VOLUME @date

Page 4: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

4

Page 5: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

5

Page 9: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

9

Page 10: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

10

鯨⿂搬運的貨櫃

在你還在打包的時候

貨櫃早就部署好了

你有想過這個嗎?

沒有

因為你只會想到你⾃⼰。

Page 11: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Foundation

11

Host OS

Hypervisor

Guest OS

Page 12: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Foundation

12

Linux Kernel

Linux Distribution FS

Page 13: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Foundation

13

Linux Kernel

Linux Distribution FS

Base Image FS

….

Page 14: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Foundation

14

Linux Kernel

Your Environments

Container

Linux Distribution FS Base Image FS

….

Page 15: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Foundation

15

Linux Kernel

Linux Distribution FS

Your Environments

Base Image FS

Images

Container

Process Process

Page 16: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Image

16

Linux Kernel

Base Image

Image Layer A

Image Layer B

Page 17: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Image

17

Linux Kernel

Base Image

Image Layer A

Image Layer B

Image Layer

Image Layer C

Image Layer

Image Layer

Page 18: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Image

18

Linux Kernel

Ubuntu

PHP 5.5

Apache

PHP 7

Nginx Apache Nginx

Page 19: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Image

19

Linux Kernel

Ubuntu

PHP 5.5

Apache

PHP 7

Nginx Apache Nginx

CentOS

Page 20: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container

20

Images

Container

Page 21: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container

Container

21

Images

Process Executing

Running

Page 22: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container

Container

22

Images

Exited (Stop)

Page 23: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container

23

Images

Changed FS

Process Executing

Host FS

Running

Page 24: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container

Container

24

Images

Changed FS

Host FS

Exited (Stop)

Page 25: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container A

Container Links

25

ContainerB

ContainerC

Page 26: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

App

Container Links

26

SQL DB Redis

Page 27: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Links Contributes

27

Page 28: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container Volumes

3f8566045a0994e.....

Host /var/www/html

…………

Container A(3f8566045a....)

Volume

Page 29: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container Volumes

Host /var/www/html

…………

Volume

/var/www/html

……

Container BVolume From

3f8566045a0994e.....

Container A(3f8566045a....)

Page 30: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container Volumes

Host

……

3f8566045a0994e.....

Page 31: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Container Volumes

Custom Directory

Host /var/www/html

…………

Container AVolume

Page 32: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Volume Contributes

32

Page 33: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

33

Page 36: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

36

Page 37: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

37

Page 38: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

38

Page 39: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
Page 40: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

40

Page 41: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

FROM php:7-apache MAINTAINER<Ruoshi Ling <[email protected]> RUN apt-get update ADD ./script.php /app/ ENTRYPOINT php CMD ["app/script.php"]

41

Page 42: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (1)

42

RUN apt-get update \ && apt-get install -y \ wget \ curl \ php5 \ && echo "Installed basic packages"

Page 43: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (2)

43

ENV APP_VERSION=1.2.3 \ DB_USER="foo" \ DB_PASSWORD="bar" \ DB_DATABASE="app" \ DB_HOST="127.0.0.1" \ ENV=production

Page 44: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (3)

44

ENV SETUP_DIR="/var/cache/app" COPY assets/setup/ ${SETUP_DIR}/ RUN bash ${SETUP_DIR}/install.sh

Page 45: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (4)

45

COPY entrypoint.sh /sbin/entrypoint.sh RUN chmod 755 /sbin/entrypoint.sh ENTRYPOINT ["/sbin/entrypoint.sh"] CMD ["app:start"]

Page 46: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (5)

46

#!/bin/bash ln -sf /data/db /var/lib/mysql ln -sf /data/uploads /app/uploads

...... VOLUME ["/data"] ENTRYPOINT ["/sbin/entrypoint.sh"]

Page 47: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Contributes

47

Page 48: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

48

compose

swarm

machine

Page 49: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

49

docker machine

Page 50: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

50

$ docker-machine create \--driver virtualbox default

Creating VirtualBox VM...Creating SSH key...Starting VirtualBox VM...Starting VM...

To see how to connect Docker to this machine, run: docker-machine env default

Page 51: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

51

$ docker-machine env default

export DOCKER_TLS_VERIFY="1"export DOCKER_HOST="tcp://192.168.99.100:2376"export DOCKER_CERT_PATH="/Users/fntsr/.docker/machine/machines/default"export DOCKER_MACHINE_NAME="default"

# Run this command to configure your shell:# eval "$(docker-machine env default)"

$ eval "$(docker-machine env default)"

Page 52: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

52

$ docker versionClient: Version: 1.8.2 ....

Server: Version: 1.8.2 API version: 1.20 Go version: go1.4.2 Git commit: 0a8c2e3 Built: Thu Sep 10 19:10:10 UTC 2015 OS/Arch: linux/amd64

Page 53: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

53

$ docker-machine create --driver ....

GenericCreate machines using

an existing VM/Host with SSH.

Page 54: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

54

Page 55: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

55

docker compose

Page 56: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

56

自從會用 Docker Compose 後,我就不再下指令了呢。

認同請分享

身體健康、萬事如意、南無阿彌陀佛 有緣認識你真好

Page 57: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

57

# Comment<service_name>: attribute: <value> attribute: - item1 - item2

Page 58: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

58

# docker-compose.ymlweb: image: php:7-fpm ports: - "5566:80" volumes: - .:/app

Page 59: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

59

# create container(s)$ docker-compose up -d

# start container(s)$ docker-compose start

# stop container(s)$ docker-compose stop

# remove container(s)$ docker-compose rm

Page 60: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

60

# docker-compose.ymlweb: build: ./ links: - mysql ports: - "9527:80"mysql: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=wordpress

Page 61: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

61

# development.ymlweb: extends: file: docker-compose.yml service: web environment: - ENV=development - DB=sqlite3

Page 62: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (1)

62

# docker-compose.ymlweb: .... environment: - DB_USER=elephant - DB_PASSWORD=ilovePHPfOEvEr - DB_DATABASE=elephant

Page 63: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (2)

63

# docker-compose.ymlweb: volumes: - ./app:/appdb: volumes: - ./db:/var/lib/mysql

Page 64: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (3)

64

# docker-compose.ymlweb: extends: file: common.yml service: web environment: - ENV=testing - DB=mysqlidb: ......

Page 65: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

Skills (4)

65

# docker-compose.ymlweb: .... restart: always

Page 66: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

`docker run`

66

Page 67: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

67

Page 68: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

68

Page 69: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

69

web: image: wordpress links: - db environment: - WORDPRESS_DB_PASSWORD=password ports: - "9527:80"db: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=wordpress

Page 70: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

70

Page 71: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

71

php5: extends: file: app.yml service: web image: php:5-fpm ports: - "11024:80" php7: extends: file: app.yml service: web image: php:7-fpm ports: - "11025:80"

Page 72: 當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

72