1.1 查看當前linux內核版本python
uname -r #linux內核要求3.10及以上
1.2 更行yum源linux
sudo yum update
1.3 若是安裝過舊版本的話,卸載舊版本docker
sudo yum remove docker docker-common docker-selinux docker-engine
1.4 安裝須要的軟件包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的shell
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
1.5 因爲國內網絡問題,建議使用國內源,添加yum軟件源ubuntu
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里雲鏡像源
已加載插件:fastestmirror, langpacks adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
1.6 能夠查看全部倉庫中全部docker版本,並選擇特定版本安裝centos
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
1.7 安裝docker安全
$ sudo yum install docker-ce #因爲repo中默認只開啓stable倉庫,故這裏安裝的是最新穩定版17.12.0 $ sudo yum install <FQPN> # 例如:sudo yum install docker-ce-17.12.1.ce
已安裝: docker-ce.x86_64 0:17.12.1.ce-1.el7.centos 做爲依賴被安裝: audit-libs-python.x86_64 0:2.8.1-3.el7 checkpolicy.x86_64 0:2.5-6.el7 container-selinux.noarch 2:2.66-1.el7 libsemanage-python.x86_64 0:2.5-11.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3 policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-2.el7 完畢!
1.8 將docker加入開機啓動bash
$ sudo systemctl start docker $ sudo systemctl enable docker
1.9 驗證安裝是否成功(有client和service兩部分表示docker安裝啓動都成功了)網絡
$ sudo docker version
Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:15:20 2018 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:54 2018 OS/Arch: linux/amd64 Experimental: false
默認狀況下,docker 命令會使用 Unix socket 與 Docker 引擎通信。而只有 root 用戶和 docker 組的用戶才能夠訪問 Docker 引擎的 Unix socket。出於安全考慮,通常 Linux 系統上不會直接使用 root 用戶。所以,更好地作法是將須要使用 docker 的用戶加入 docker 用戶組。
2.1 創建docker組app
$ sudo groupadd docker
2.2 將當前用戶加入 docker 組:
$ sudo usermod -aG docker $USER
2.3 退出當前終端並從新登陸,進行以下測試。
$ docker version #無需sudo使用管理員權限
Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:15:20 2018 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:54 2018 OS/Arch: linux/amd64 Experimental: false
$ docker run hello-world #運行hello world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9db2ca6ccae0: Pull complete Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
$ docker image ls #列出鏡像
倉庫名 標籤 鏡像ID 建立時間 佔用空間 REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 2cb0d9787c4d 2 weeks ago 1.85kB