最近在linux內核為3.10的系統上構建鏡像之后移植到centos內核為2.6.32-642.el6.x86_64上去導入和創建容器成功了
舊版本docker安裝參考:https://www.cnblogs.com/lonecloud/p/7392456.html
==========================================================================
使用 sudo 或 root 權限的用戶登入終端
①先確認linux系統版本是否滿足安裝要求:
Docker運行的平台是什么?
Linux的:
- 運行Linux內核版本3.10+的任何發行版
- 大多數Linux發行版都有特定的說明,包括 RHEL,Ubuntu, Oracle Linux, SuSE等等。
微軟Windows:
- Windows Server 2016
- Windows 10
目前,CentOS 僅發行版本中的內核支持 Docker。
Docker 運行在 CentOS 7 上,要求系統為64位、系統內核版本為 3.10 以上。
②理解docker的幾個核心概念:
鏡像:類似虛擬機的鏡像、用俗話說就是安裝文件。
容器:類似一個輕量級的沙箱,容器是從鏡像創建應用運行實例,
可以將其啟動、開始、停止、刪除、而這些容器都是相互隔離、互不可見的。
倉庫:類似代碼倉庫,是Docker集中存放鏡像文件的場所
按照網上的教程安裝了docker后來發現安裝的是舊版本的docker-engine,查閱官方文檔重新安裝
卸載舊版本docker-engine:
[root@localhost etc]# yum remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-logrotate \ > docker-engine
卸載docker -ce版本的方法:
yum remove docker-ce
1.檢查內核版本,返回的值大於3.10即可。
[root@localhost etc]# uname -r 3.10.0-693.el7.x86_64
2.升級yum到最新
yum update
3.yum 倉庫添加docker源信息
步驟一:安裝所需的程序(Install required packages. yum-utils
provides the yum-config-manager
utility, and device-mapper-persistent-data
and lvm2
are required by the devicemapper
storage drive)
[root@izwz92fbqxna6qt4ya9t4nz conf]# yum install -y yum-utils device-mapper-persistent-data lvm2
步驟二:添加docker源
[root@izwz92fbqxna6qt4ya9t4nz conf]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4.安裝docker(不指定版本則默認安裝所配源倉庫的最新版本):
情況一:直接安裝
yum install -y docker-ce
官網這個地方還安裝了docker-ce-cli和containerd.io
,但是我直接執行上面的安裝命令,發現這兩個工具也安裝了
yum install docker-ce docker-ce-cli containerd.io
[root@izwz92fbqxna6qt4ya9t4nz soft]# yum install docker-ce-cli containerd.io Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Package 1:docker-ce-cli-18.09.2-3.el7.x86_64 already installed and latest version Package containerd.io-1.2.2-3.3.el7.x86_64 already installed and latest version Nothing to do
情況二:安裝指定版本
查看所有版本及版本信息
[root@izwz92fbqxna6qt4ya9t4nz soft]# yum list docker-ce --showduplicates | sort -r Loading mirror speeds from cached hostfile Loaded plugins: fastestmirror Installed Packages docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.2-3.el7 @docker-ce-stable docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
選擇版本安裝
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
5.檢查docker是否安裝成功:
[root@izwz92fbqxna6qt4ya9t4nz soft]# docker -v Docker version 18.09.2, build 6247962
6.啟動docker:
[root@localhost etc]# systemctl start docker
#有些系統是service docker start
啟動之后執行docker version可以看到客戶端和服務端的相關信息,不啟動的時候只能看到客戶端的信息
[root@izwz92fbqxna6qt4ya9t4nz soft]# docker version Client: Version: 18.09.2 API version: 1.39 Go version: go1.10.6 Git commit: 6247962 Built: Sun Feb 10 04:13:27 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.2 API version: 1.39 (minimum version 1.12) Go version: go1.10.6 Git commit: 6247962 Built: Sun Feb 10 03:47:25 2019 OS/Arch: linux/amd64 Experimental: false
7.檢查docker是否啟動成功:
[root@localhost etc]# ps -ef | grep docker root 28623 1 0 10:25 ? 00:00:06 /usr/bin/dockerd root 28632 28623 0 10:25 ? 00:00:04 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc root 29726 19746 0 11:24 pts/2 00:00:00 grep --color=auto docker
8.設置開機啟動:
[root@localhost etc]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
官網通過運行hello-world
鏡像驗證是否正確安裝了Docker CE 。
docker run hello-world
此命令下載測試鏡像並在容器中運行它。當容器運行時,它會打印一條信息性消息並退出。注意,如果網絡不好,可能不會一次成功,我搭建了2套環境,其中一套就是執行了很多次才成功