Docker安裝 - CentOS7環境

Docker安裝 - CentOS7環境

 

 

安裝Docker

我是虛擬機裝的Centos7,linux 3.10 內核,docker官方說至少3.8以上,建議3.10以上(ubuntu下要linux內核3.8以上, RHEL/Centos 的內核修補過, centos6.5的版本就能夠——這個能夠試試)html

1. root帳戶登陸,查看內核版本以下linux

 

[root@localhost ~]# uname -a
Linux localhost.qgc 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

 

 

 

2. 把yum包更新到最新 docker

[root@localhost ~]# yum update
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: centos.ustc.edu.cn
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 bind-libs.x86_64.32.9.9.4-61.el7 將被 升級
---> 軟件包 bind-libs.x86_64.32.9.9.4-61.el7_5.1 將被 更新
---> 軟件包 bind-libs-lite.x86_64.32.9.9.4-61.el7 將被 升級
---> 軟件包 bind-libs-lite.x86_64.32.9.9.4-61.el7_5.1 將被 更新
---> 軟件包 bind-license.noarch.32.9.9.4-61.el7 將被 升級
---> 軟件包 bind-license.noarch.32.9.9.4-61.el7_5.1 將被 更新
...
...
驗證中 : 32:bind-license-9.9.4-61.el7.noarch 8/8
更新完畢:
  bind-libs.x86_64 32:9.9.4-61.el7_5.1                                        
  bind-libs-lite.x86_64 32:9.9.4-61.el7_5.1                                   
  bind-license.noarch 32:9.9.4-61.el7_5.1                                     
  bind-utils.x86_64 32:9.9.4-61.el7_5.1                                       
完畢!
[root@localhost ~]#

 

 

3. 安裝須要的軟件包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的ubuntu

 

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: centos.ustc.edu.cn
...

 

 

4. 設置yum源centos

[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
已加載插件:fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

 

 

 

5. 能夠查看全部倉庫中全部docker版本,並選擇特定版本安裝bash

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加載插件:fastestmirror, langpacks
可安裝的軟件包
 * updates: centos.ustc.edu.cn
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
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
...

 

 

6. 安裝Docker,命令:yum install docker-ce-版本號,我選的是17.12.1.ce,以下app

[root@localhost ~]# yum install docker-ce-17.12.1.ce
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: centos.ustc.edu.cn
base                                                   | 3.6 kB     00:00     
docker-ce-stable                                       | 2.9 kB     00:00     
extras                                                 | 3.4 kB     00:00     
updates                                                | 3.4 kB     00:00     
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 docker-ce.x86_64.0.17.12.1.ce-1.el7.centos 將被 安裝
--> 正在處理依賴關係 container-selinux >= 2.9,它被軟件包 docker-ce-17.12.1.ce-1.el7.centos.x86_64 須要
...

 

 

7.啓動Docker,命令:systemctl start docker,而後加入開機啓動,以下ui

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

 

 

 

8. 驗證安裝是否成功(有client和service兩部分表示docker安裝啓動都成功了)spa

[root@localhost ~]# 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命令,更多命令詳解,請訪問:http://www.docker.org.cn/dockerppt/106.html:插件

 

 -----------------     docker ps 查看當前正在運行的容器 

 -----------------    docker ps -a 查看全部容器的狀態 

 -----------------    docker start/stop id/name 啓動/中止某個容器 

 -----------------    docker attach id 進入某個容器(使用exit退出後容器也跟着中止運行) 

 -----------------    docker exec -ti id 啓動一個僞終端以交互式的方式進入某個容器(使用exit退出後容器不中止運行) 

 -----------------    docker images 查看本地鏡像

 -----------------    docker rm id/name 刪除某個容器

-----------------     docker rmi id/name 刪除某個鏡像 

 -----------------    docker run --name test -ti ubuntu /bin/bash  複製ubuntu容器而且重命名爲test且運行,而後以僞終端交互式方式進入容器,運行bash 

-----------------     docker build -t soar/centos:7.1 .  經過當前目錄下的Dockerfile建立一個名爲soar/centos:7.1的鏡像 

 -----------------    docker run -d -p 2222:22 --name test soar/centos:7.1  以鏡像soar/centos:7.1建立名爲test的容器,並之後臺模式運行,並作端口映射到宿主機2222端口,P參數重啓容器宿主機端口會發生改變

 

 

 

 

 

 

 

 

 

 

 

 

參考:https://www.cnblogs.com/qgc1995/archive/2018/08/29/9553572.html

 參考:http://www.javashuo.com/article/p-aptrhsrk-dp.html

參考:http://www.docker.org.cn/dockerppt/106.html

相關文章
相關標籤/搜索