安裝 Docker
1. 更新 Ubuntu 14.04 最新套件清單及系統升級
$ sudo apt-get update
$ sudo apt-get upgrade
2. 開始安裝 docker
$ wget -qO- https://get.docker.com/ | sh
3. 將 bigred 加入 docker 群組
$ sudo usermod -aG docker bigred
3. 將 bigred 加入 docker 群組
$ sudo usermod -aG docker bigred
4. 檢視 docker 版本 (2015/01/01)
$ docker -v
Docker version 1.8.3, build f4bf5c7
5. 檢視 Docker Engine
Docker 套件安裝完成後, 會自動在系統中, 啟動 Docker Engine, 檢視命令如下 :
$ ps aux | grep 'docker \-d'
root 1407 0.0 0.3 331096 10468 ? Ssl 12:38 0:00 /usr/bin/docker -d
Docker Engine 這個系統服務, 主要負責管理 Docker Container, 當 Docker Engine 啟動 Container時, Docker Engine 會幫 Docker Container 配置 Kernel Namespace, aufs 及 虛擬網卡 (連接 docker0 橋接器), 使得 Container 會被隔離在一個獨立運作空間運行.
6. 檢視 Docker 工作目錄
$ sudo tree -L 2 /var/lib/docker/
/var/lib/docker/
├── aufs
│ ├── diff
│ ├── layers
│ └── mnt
├── containers
│ ├── 068ff6c1108dfb5df70011c0a04d22be95ebe3f38afa8bdb5eae035e032e0443
│ ├── 0a8796835a872f88428ac5871712ec4eb63d2e6bfb3ccbd5bb74d21aef088ab7
│ ├── 10d3032101962265fc499ac0179a5ba001947526dcfabbf77db4fa8b3b0bf484
::
│ ├── e6f673326443820c1804ceaf50ae354a8e3be2b373c78587ab11cbf7435bf289
│ ├── ef7e1ef4d1d2d12e44389efc581884bb930088cf1c51a6d40903499e986bbe2a
│ └── f82b2aa8a958d3f82dea09409c79c0cc724a341639da4bdc08b161a36b256e1b
├── graph
│ ├── 51ab123e5709f69fc0ed7cce8f45f70bb65e212435f7b07f9f7a3a1f284e3a0f
│ ├── 76c3a176cb278cc608bc6448aba0ba3597ec5495ca2f874f420a38516623e249
│ ├── 932d5e9473735e05bee20bc03e3ee5f3d61b7ce7561c2f52aa508fe3504fd3c7
│ ├── 9edd2e42e620c1e9cc3ab477b60a1f7690b60b880febb89e5eb15f5b828adcf0
│ ├── a70d50cbb5ae2381bd09f882c63a97c016b8a12e70be056d6ad26af6870525d2
│ ├── b3584fc79604203ff792ee1a01de05877f5e2f2efcdf0bdff5bd74f0b8da123f
│ ├── b3c5954fa6e663cffffbda5f3215af11dce5c178d8e6dfd61a692d76dc1c718e
│ ├── b6af470ae058eabe8722937bff96b573e4a04262094a9b3239f3bab24910bdf6
│ ├── e8c52fd331562b90f36f494a6ddff50e6e1348034982c782c302a97aec31c37c
│ ├── f45152be9b63d713a6a42c92bcfa282fd6402ed9ba9fe41fb34c619efb580b9a
│ └── _tmp
├── linkgraph.db
├── repositories-aufs
├── tmp
│ └── GetImageBlob292711047
├── trust
└── volumes
$ sudo apt-get install bridge-utils
套件安裝完成後, 便可執行以下命令, 檢視 docker0 橋接器資訊
$ brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.56847afe9799 no
在橋接網路規劃上, 內定配置的 IP 範圍, 是一個 Private Class B (172.17.0.0/16) , 由以下命令可以得知 docker0 橋接器 內建網卡的 IP 位址.
$ ifconfig docker0
docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
使用 Docker Container (貨櫃系統)$ docker -v
Docker version 1.8.3, build f4bf5c7
5. 檢視 Docker Engine
Docker 套件安裝完成後, 會自動在系統中, 啟動 Docker Engine, 檢視命令如下 :
$ ps aux | grep 'docker \-d'
root 1407 0.0 0.3 331096 10468 ? Ssl 12:38 0:00 /usr/bin/docker -d
Docker Engine 這個系統服務, 主要負責管理 Docker Container, 當 Docker Engine 啟動 Container時, Docker Engine 會幫 Docker Container 配置 Kernel Namespace, aufs 及 虛擬網卡 (連接 docker0 橋接器), 使得 Container 會被隔離在一個獨立運作空間運行.
6. 檢視 Docker 工作目錄
$ sudo tree -L 2 /var/lib/docker/
/var/lib/docker/
├── aufs
│ ├── diff
│ ├── layers
│ └── mnt
├── containers
│ ├── 068ff6c1108dfb5df70011c0a04d22be95ebe3f38afa8bdb5eae035e032e0443
│ ├── 0a8796835a872f88428ac5871712ec4eb63d2e6bfb3ccbd5bb74d21aef088ab7
│ ├── 10d3032101962265fc499ac0179a5ba001947526dcfabbf77db4fa8b3b0bf484
::
│ ├── e6f673326443820c1804ceaf50ae354a8e3be2b373c78587ab11cbf7435bf289
│ ├── ef7e1ef4d1d2d12e44389efc581884bb930088cf1c51a6d40903499e986bbe2a
│ └── f82b2aa8a958d3f82dea09409c79c0cc724a341639da4bdc08b161a36b256e1b
├── graph
│ ├── 51ab123e5709f69fc0ed7cce8f45f70bb65e212435f7b07f9f7a3a1f284e3a0f
│ ├── 76c3a176cb278cc608bc6448aba0ba3597ec5495ca2f874f420a38516623e249
│ ├── 932d5e9473735e05bee20bc03e3ee5f3d61b7ce7561c2f52aa508fe3504fd3c7
│ ├── 9edd2e42e620c1e9cc3ab477b60a1f7690b60b880febb89e5eb15f5b828adcf0
│ ├── a70d50cbb5ae2381bd09f882c63a97c016b8a12e70be056d6ad26af6870525d2
│ ├── b3584fc79604203ff792ee1a01de05877f5e2f2efcdf0bdff5bd74f0b8da123f
│ ├── b3c5954fa6e663cffffbda5f3215af11dce5c178d8e6dfd61a692d76dc1c718e
│ ├── b6af470ae058eabe8722937bff96b573e4a04262094a9b3239f3bab24910bdf6
│ ├── e8c52fd331562b90f36f494a6ddff50e6e1348034982c782c302a97aec31c37c
│ ├── f45152be9b63d713a6a42c92bcfa282fd6402ed9ba9fe41fb34c619efb580b9a
│ └── _tmp
├── linkgraph.db
├── repositories-aufs
├── tmp
│ └── GetImageBlob292711047
├── trust
└── volumes
認識 Docker 網路
Docker 套件安裝完成後, 它會自動建立一個名為 docker0 虛擬橋接器, 在 Ubuntu 系統中, 要檢視此 橋接器資訊, 你會需要安裝 bridge-utils 套件, 命令如下 :
$ sudo apt-get install bridge-utils
$ brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.56847afe9799 no
在橋接網路規劃上, 內定配置的 IP 範圍, 是一個 Private Class B (172.17.0.0/16) , 由以下命令可以得知 docker0 橋接器 內建網卡的 IP 位址.
$ ifconfig docker0
docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
要啟動 Container 首先必須先取得它的系統母體, 這系統母體稱之為 Docker Image, 如用 Java 語言來比喻, Docker Image 相當於 Java 類別檔(設計藍圖), Container 相當於根據 Java 類別檔實作的物件
1. 下載 Docker 官方 Ubuntu 及 CentOS Base Image
$ sudo docker pull ubuntu
ubuntu:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
fe95bf7d5f50: Pull complete
9a4594fe74ea: Pull complete
8c4b1edcceea: Pull complete
ed5a78b7b42b: Pull complete
Status: Downloaded newer image for ubuntu:latest
$ sudo docker pull ubuntu:12.04
ubuntu:12.04: The image you are pulling has been verified
bc1f0427b833: Pull complete
0cf29d6c76b4: Pull complete
b560c37f1efa: Pull complete
69c02692b0c1: Pull complete
511136ea3c5a: Already exists
Status: Downloaded newer image for ubuntu:12.04
centos:latest: The image you are pulling has been verified
5b12ef8fd570: Pull complete
8efe422e6104: Pull complete
511136ea3c5a: Already exists
Status: Downloaded newer image for centos:latest
2. 檢視 Docker image 資訊
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 5ba9dab47459 7 days ago 188.3 MB
ubuntu 12.04 69c02692b0c1 7 days ago 131.3 MB
centos latest 8efe422e6104 4 weeks ago 210 MB
3. 根據 Ubuntu image 建立及啟動你的第一個 Container
$ sudo docker run -i -t ubuntu /bin/bash
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 5ba9dab47459 7 days ago 188.3 MB
ubuntu 12.04 69c02692b0c1 7 days ago 131.3 MB
centos latest 8efe422e6104 4 weeks ago 210 MB
$ sudo docker run -i -t ubuntu /bin/bash
4. 檢視 Container 的 IP 位址
root@7a4e583aaee1:/# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 02:42:c0:a8:00:03
inet addr:172.17.0.13 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:c0ff:fea8:3/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:578 (578.0 B)
5. 停止 Container
root@7a4e583aaee1:/# exit
exit
6. 檢視已建立 Container
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2b728b5eb3f ubuntu:latest "/bin/bash" 8 minutes ago Exited (0) 5 minutes ago mad_darwin
eth0 Link encap:Ethernet HWaddr 02:42:c0:a8:00:03
inet addr:172.17.0.13 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:c0ff:fea8:3/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:578 (578.0 B)
5. 停止 Container
root@7a4e583aaee1:/# exit
exit
6. 檢視已建立 Container
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2b728b5eb3f ubuntu:latest "/bin/bash" 8 minutes ago Exited (0) 5 minutes ago mad_darwin
$ sudo docker rm a2b
a2b
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
管理 Docker Image
1. 建立 mysh Container
$ sudo docker run --name mysh -i -t dafu/busybox /bin/sh
2. 建立目錄, 離開 mysh Container
~ # mkdir test
~ # exit
3. 產生 ????/mysh Image
$ sudo docker commit mysh dafu/mysh
3457c66d9321f79442729769487a6f0351733af1b8aecda10b64fcfd6999e9c7
4. 登入 Docker HUB 網站
$ sudo docker login
Username: ????
Password:
Email: ?????????
WARNING: login credentials saved in /home/bigred/.docker/config.json
Login Succeeded
5. 上傳 自製 Docker Image
$ sudo docker push dafu/mysh
The push refers to a repository [docker.io/dafu/mysh] (len: 1)
3457c66d9321: Image successfully pushed
bdfd75a75b02: Image successfully pushed
latest: digest: sha256:2fe7fb641a885cf78b4225e6e8b56cf2fb04f7cd7b402e4c45198babc5061e05 size: 2416
6. 搜尋 Docker Image
$ sudo docker search dafu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
dafu/dkutil Docker utilities for Hadoop Ecosystem 0
dafu/hadoop Hadoop 生態系統套件 0
dafu/bigdata Big Data ecosystem : Base System (Ubuntu 1... 0
dafu/mysql 0
dafu/mysh 0
1. 建立 mysh Container
$ sudo docker run --name mysh -i -t dafu/busybox /bin/sh
2. 建立目錄, 離開 mysh Container
~ # mkdir test
~ # exit
3. 產生 ????/mysh Image
$ sudo docker commit mysh dafu/mysh
3457c66d9321f79442729769487a6f0351733af1b8aecda10b64fcfd6999e9c7
4. 登入 Docker HUB 網站
$ sudo docker login
Username: ????
Password:
Email: ?????????
WARNING: login credentials saved in /home/bigred/.docker/config.json
Login Succeeded
5. 上傳 自製 Docker Image
$ sudo docker push dafu/mysh
The push refers to a repository [docker.io/dafu/mysh] (len: 1)
3457c66d9321: Image successfully pushed
bdfd75a75b02: Image successfully pushed
latest: digest: sha256:2fe7fb641a885cf78b4225e6e8b56cf2fb04f7cd7b402e4c45198babc5061e05 size: 2416
6. 搜尋 Docker Image
$ sudo docker search dafu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
dafu/dkutil Docker utilities for Hadoop Ecosystem 0
dafu/hadoop Hadoop 生態系統套件 0
dafu/bigdata Big Data ecosystem : Base System (Ubuntu 1... 0
dafu/mysql 0
dafu/mysh 0
沒有留言:
張貼留言