2015/03/08

CentOS 7 的 Docker 服務安裝

# Install Docker in CentOS 7 , lsb_release 確定一下目前的 linux 版本
[mtchang@mtchang ~]$ sudo lsb_release -a
LSB Version:        :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:        CentOS
Description:        CentOS Linux release 7.0.1406 (Core)
Release:        7.0.1406
Codename:        Core
# 直接安裝 docker 和 docker-registry
[mtchang@mtchang ~]$ sudo yum -y install docker docker-registry
# 在 centos 7 使用 systemctl 管控 docker.service ,這裡是把服務預設開機啟動
[mtchang@mtchang ~]$ sudo systemctl enable docker.service
ln -s '/usr/lib/systemd/system/docker.service' '/etc/systemd/system/multi-user.target.wants/docker.service'
# 手動啟用 docker service
[mtchang@mtchang ~]$ sudo systemctl start docker.service
# 驗證是否已經啟動
[mtchang@mtchang ~]$ sudo systemctl status docker.service
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled)
   Active: active (running) since Sat 2015-02-21 15:22:01 CST; 15s ago
     Docs: http://docs.docker.com
 Main PID: 4346 (docker)
   CGroup: /system.slice/docker.service
           └─4346 /usr/bin/docker -d --selinux-enabled -H fd://
Feb 21 15:21:51 mtchang docker[4346]: 2015/02/21 15:21:51 docker daemon: 1.3.2 39fa2fa/1.3.2; execdriver: nat...iver:
Feb 21 15:21:51 mtchang docker[4346]: [aec76134] +job serveapi(fd://)
Feb 21 15:21:51 mtchang docker[4346]: [info] Listening for HTTP on fd ()
Feb 21 15:22:00 mtchang docker[4346]: [aec76134] +job init_networkdriver()
Feb 21 15:22:00 mtchang docker[4346]: [aec76134] -job init_networkdriver() = OK (0)
Feb 21 15:22:01 mtchang docker[4346]: [info] Loading containers:
Feb 21 15:22:01 mtchang docker[4346]: [info] : done.
Feb 21 15:22:01 mtchang docker[4346]: [aec76134] +job acceptconnections()
Feb 21 15:22:01 mtchang docker[4346]: [aec76134] -job acceptconnections() = OK (0)
Feb 21 15:22:01 mtchang systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
# 從 docker registry 抓取 ubuntu 的影像檔案
[mtchang@mtchang ~]$ sudo docker pull ubuntu
Pulling repository ubuntu
2d24f826cb16: Download complete
511136ea3c5a: Download complete
fa4fd76b09ce: Download complete
1c8294cc5160: Download complete
117ee323aaa9: Download complete
Status: Downloaded newer image for ubuntu:latest
# docker run 指令執行以 ubuntu 影像檔為基礎的一個 container
# mtchang@mt ~ $ sudo docker run --help
# 語法: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
# -i 可以保持 STDIN 輸出訊息打開
# -t 可以取得一個 pseudo-TTY (虛擬終端機界面)
[mtchang@mtchang ~]$ sudo docker run -i -t ubuntu /bin/bash
# 已經切換到docker container 內, ip 也變換成為虛擬網段 172.17.0.xx。
root@bc44ac88d7a4:/# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02
          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:19 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2173 (2.1 KB)  TX bytes:508 (508.0 B)
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  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)
root@bc44ac88d7a4:/#  exit
exit
張貼留言