1. 程式人生 > >Docker入門-安裝(一)

Docker入門-安裝(一)

Docker 

在CentOS 7.0下安裝Docker, CentOS 7.0預設使用的是firewall作為防火牆

  • 檢視防火牆狀態
    firewall-cmd --state
  • 停止firewall
    systemctl stop firewalld.service
  • 啟動firewall
    systemctl start firewalld.service
  • 禁止firewall開機啟動
    systemctl disable firewalld.service

1.移除舊版本:

yum remove docker \
          docker-client \
          docker-client-latest \
          docker-common \
          docker-latest \
          docker-latest-logrotate \
          docker-logrotate \
          docker-selinux \
          docker-engine-selinux \
          docker-engine

2.安裝必要依賴:

yum install -y yum-utils device-mapper-persistent-data lvm2

3.更換國內映象:

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4.更新 yum 快取:

yum makecache fast

5.安裝 Docker-ce:

yum -y install docker-ce

6.啟動 Docker 後臺服務

systemctl start docker

7.測試執行 hello-world

docker run hello-world

8.執行互動式容器

[email protected]:~$ docker run -it ubuntu:15.10 /bin/bash
[email protected]:/#
  • -i:允許你對容器內的標準輸入進行互動
  • -t:在新容器內指定一個偽終端或終端
  • -d: 後臺啟動容器
  • –rm:容器退出後立即刪除容器。一般情況下,無需指定此引數,指定--rm可以避免浪費空間

退出容器互動命令 ctrl+d

9.後臺執行容器

[email protected]:~$ docker run -d ubuntu:15.10 /bin/bash
[email protected]:/#

10.檢視執行的容器

[[email protected] ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
46353af5c8ce        ubuntu:15.10        "/bin/bash"         4 minutes ago       Up 4 minutes                            gracious_allen

11.停止容器

[[email protected] ~]# docker stop 46353af5c8ce
46353af5c8ce

12.檢視本機映象

[[email protected] ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
zookeeper           latest              f336949ce7a1        6 weeks ago         148MB
hello-world         latest              4ab4c602aa5e        3 months ago        1.84kB
ubuntu              15.10               9b9cb95443b5        2 years ago         137MB
training/webapp     latest              6fae60ef3446        3 years ago         349MB

結構說明:

  • REPOSITORY:倉庫名稱
  • TAG:標籤名稱
  • IMAGE ID:映象ID
  • CREATED:建立時間
  • SIZE:所佔用的空間

列出指定映象

[[email protected] ~]# docker image ls ubuntu
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              15.10               9b9cb95443b5        2 years ago         137MB

13.刪除映象

[[email protected] ~]# docker image rm 6fae60ef3446

14.查詢映象

[[email protected] ~]# docker search ubuntu 
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                 Ubuntu is a Debian-based Linux operating sys…   8910                [OK]                
dorowu/ubuntu-desktop-lxde-vnc                         Ubuntu with openssh-server and NoVNC            253                                     [OK]
rastasheep/ubuntu-sshd                                 Dockerized SSH service, built on top of offi…   187                                     [OK]