前端工程師一定要知道的 Docker 虛擬化容器技巧

  • View
    4.153

  • Download
    1

  • Category

    Software

Preview:

Citation preview

[ chusiang@takaojs ~ ] $ cat .profile # / chusiang.lai (at) gmail.com / http://note.drx.tw

3

OutlineI.

4

OutlineI.

II.

5

OutlineI.

II.

III. Docker

6

OutlineI.

II.

III. Docker

IV. Docker

7

OutlineI.

II.

III. Docker

IV. Docker

V. 12 Docker

8

OutlineI.

II.

III. Docker

IV. Docker

V. 12 Docker

VI. Q & A

9

Ⅰ.

10

11

JavaScript

jQueryRWD Git

Sublime Text

VimHTML5CSS

Node.js

JSON

FirefoxSafari

ChromeIE

Django

PHP

Laravel

SkitchPythonUI

UX

Ⅱ.

12

※ Docker (container)

Docker

- http://goo.gl/ZFjhT013

Ⅲ. Docker

14

Docker

15

2014 Docker IT

Docker

Docker Container

Docker IT

iThome - http://goo.gl/lJPQLF16

Docker

17

Docker VM N Guest OS

Server

Host OS

Hypervisor

Guest OS Guest OS

Bins/Libs Bins/Libs

App A App B

VM 1 VM 2

Server

Host OS

Docker Engine

Bins/Libs Bins/Libs

App A App B

Container 1 Container 2

18

Docker

19

container container

image image

Docker Registry1. Registry image

2. image container

5. image Registry

4. container

image

3. Infrastructure

Docker

20

container container

image image

Docker Registry1. Registry image

2. image container

5. image Registry

4. container

image

3. Infrastructure

Docker

21

container container

image image

Docker Registry1. Registry image

2. image container

5. image Registry

4. container

image

3. Infrastructure

Docker

22

container container

image image

Docker Registry1. Registry image

2. image container

5. image Registry

4. container

image

3. Infrastructure

Docker

23

container container

image image

Docker Registry1. Registry image

2. image container

5. image Registry

4. container

image

3. Infrastructure

Ⅳ. Docker

24

GNU/Linux

25

WindowsmacOS

Ubuntu Docker - http://goo.gl/klHIyP

Windows Docker - https://goo.gl/pVrGFZ

Ⅴ. 12 Docker

29

Terminal and

30

Kitematic

Terminal and Kitematic

Lv1

1 (pull)

34

# docker pull [OPTIONS] NAME[:TAG|@DIGEST]

$ docker pull chusiang/takaojs1607Using default tag: latestlatest: Pulling from chusiang/takaojs160720d99f5aec05: Already exists72f7fcd433f8: Already exists5dce81f870ab: Already existsa3ed95caeb02: Already exists23f18164665f: Already exists282006c4409e: Already exists3472ef26cc6d: Already exists16de7d488a57: Already existsa3ed95caeb02: Already exists5783f1e0c823: Already exists...Digest: sha256:ce3c8ed58945808496447b9237c3d1e014edebe5c3200901621d73458be9395cStatus: Downloaded newer image for chusiang/takaojs1607:latest

2 (images)

35

# docker images [OPTIONS] [REPOSITORY[:TAG]]

$ docker imagesREPOSITORY TAG MAGE ID CREATED SIZEchusiang/takaojs1607 latest 3ad250eb94d2 About an hour ago 1.307 GBtakaojs1607 latest 94714eb3e147 2 hours ago 1.307 GBchusiang/gitbook latest 1aa2bbe894cb 8 days ago 696 MBdebian latest 1b088884749b 2 weeks ago 125.1 MBcentos centos6 6a77ab6655b9 3 weeks ago 194.6 MBubuntu 14.04 8f1bd21bd25c 4 weeks ago 188 MBmemcached latest 8e1d5f409061 7 weeks ago 132.2 MBubuntu latest b72889fa879c 10 weeks ago 188 MBnginx latest eb4a127a1188 11 weeks ago 182.7 MBdebian wheezy ddbdfa5a014a 12 weeks ago 84.89 MBhello-world latest 690ed74de00f 8 months ago 960 Bdocker/whalesay latest 6b362a9f73eb 13 months ago 247 MB

3 (run)

36

# docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

# - 3.1. #$ docker run -it chusiang/takaojs1607 bashroot@fff0cdc8035a:/tmp# exitexit

# - 3.2. daemon #$ docker run -it -d chusiang/takaojs1607 tail -f /dev/null473e79f71ed34c3a88cb1def191a241962357952b5c7627b5600...

# - 3.3. (local container )#$ docker run -it -v ~/Downloads:/data chusiang/takaojs1607 bashroot@cc0345c6ccda:/tmp# exitexit

Lv2

37

4 (ps)zz

38

# docker ps [OPTIONS]

# - 4.1. containers#$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESfff0cdc8035a chusiang/takaojs1607 "tail -f /dev/null" 1 hours ago Up 1 hours cranky_bose

# - 4.2. containers## -a, --all Show all containers (default shows just running)#$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESfff0cdc8035a chusiang/takaojs1607 "bash" 1 hours ago Exited (0) 1 hours ago stoic_euler473e79f71ed3 chusiang/takaojs1607 "tail -f /dev/null" 1 hours ago Up 1 hours cranky_bose

5 (stop)

39

# docker stop [OPTIONS] CONTAINER [CONTAINER...]

$ docker stop 473e79f71ed3473e79f71ed3

$ docker ps

# docker start [OPTIONS] CONTAINER [CONTAINER...]

$ docker start 473e79f71ed3473e79f71ed3

$ docker ps

6 (start)

Lv3

40

7 (exec)

41

# docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

# containers$ docker ps

# container$ docker exec -it 473e79f71ed3 bash

# container root@473e79f71ed3:/tmp# lsb_release -a > hello_world.txt

# containerroot@473e79f71ed3:/tmp# exit

8 image (commit)

42

# docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

$ docker ps

$ docker commit 473e79f71ed3 takaojs1607sha256:df58b57acb0f10cd8321fa9174becbb19d75463a63354cd11d43debd...

$ docker ps

# -a, --author string Author# -m, --message string Commit message#$ docker commit -m " " -a " " 473e79f71ed3 takaojs1607sha256:5a2fd19723027fb305beb749ad5114775db8824d4d5d51d89bd04d01...

9 (tag)

43

# docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]## image$ docker images

# IMAGE ID tag$ docker tag 5a2fd1972302 takaojs1607:1.0$ docker images

# REPOSITORY tag$ docker tag takaojs1607 takaojs1607:1.1$ docker images

$ docker tag takaojs1607:latest takaojs1607:1.2$ docker images

Lv4

44

10 image tag (rmi)

45

# docker rmi [OPTIONS] IMAGE [IMAGE...]

# IMAGE ID image$ docker images$ docker rmi 473e79f71ed3

# tag$ docker images$ docker rmi takaojs1607:1.2$ docker image

# ( )$ docker run hello-world$ docker rmi -f hello-world

11 (rm)

46

# docker rm [OPTIONS] CONTAINER [CONTAINER...]

$ docker ps -a

# $ docker rm 473e79f71ed3root@473e79f71ed3:/tmp#

# $ docker rm -f 473e79f71ed3

12 image (push)

47

# docker push NAME[:TAG] [OPTIONS]# # - Docker Registry # - Docker Hub: <USERNAME>/<REPO_NAME># - Private Docker Registry: <SERVER_NAME>/<REPO_NAME>

$ docker images

$ docker tag 473e79f71ed3 <USERNAME>/foo$ docker tag 473e79f71ed3 <SERVER_NAME>/foo

# image$ docker push <USERNAME>foo$ docker push <SERVER_NAME>/foo

Live Demo

48

https://hub.docker.com/r/chusiang/takaojs1607/

https://youtu.be/XqCt8gk9AdI

51

1/3

52

Q & A

54

55

56

http:// .tw

DevOps Taiwan

https://www.facebook.com/groups/DevOpsTaiwan/

https://devopstaiwan.slack.com/

https://gitter.im/DevOpsTW/

http://www.vim.tw

http://coscup.org

http://mopcon.org

• Docker Overview - https://docs.docker.com/engine/understanding-docker/

• Docker —— | GitBook - https://goo.gl/RIN20W

• chusiang/takaojs1607-docker-demo: docker demo for takaojs meetup | GitHub - https://github.com/chusiang/takaojs1607-docker-demo

• selenium/standalone-chrome-debug | Docker Hub - https://goo.gl/hWDwVI

• angular/angular-seed | GitHub - https://goo.gl/gWzUJp

• start | npm Documentation - https://docs.npmjs.com/cli/start

• Selenium docker debug | Smlsun - http://blog.smlsun.com/2015/04/selenium-docker-debug.html

• Docker - http://www.slideshare.net/appleboy/docker-61214768

61

Free

• Find & run the whalesay image | Docker Docs - https://goo.gl/NSQmjJ

• - - - http://goo.gl/lMOqhW

• LCL shipments and container transportation | Flamingo shipping - http://goo.gl/Ouufei

• - 94 - http://goo.gl/ZFjhT0

• Docker Containers and Kubernetes, Smart ecosystem solution to virtualize in the Cloud | Yasser Yassin - https://goo.gl/o8tUfx

• Microsoft Announces Docker Command Line Interface for Windows Clients | 1800Pocket/PC - http://goo.gl/fsY1yR

• Cloud Backup stew in Docker container? Check – Asigra • The Register - http://goo.gl/Zu955T

• Apple Mac Logo Evolution With Apple Mac Startup Sound Evolution 3 - YouTube - https://goo.gl/rXa8Mo

• File:Windows logo - 2006.svg - Wikipedia - https://goo.gl/c2zYDh

• | Docker —— - https://goo.gl/CVAzZe

• How Docker Turbocharged Uber's Deployments | The New Stack - http://goo.gl/EIftQe

• AngularJS Meets Salesforce1 - https://scottbcovert.github.io/angularjs-meets-salesforce1/#/2

• "Node.js Logo" Posters by th1341 | Redbubble - http://goo.gl/on0lYO

• Now Hiring: QA Engineer w/ Selenium | Boyle Software - http://goo.gl/p3ZdNf

62

END

Recommended