目前Docker新版本docker-ce官宣支持的CentOS系统为7及以上系统,CentOS 6.X由于内核版本太低,为2.6,所以不支持,如果想要在6.X安装docker-ce就需要升级内核到3.X。CentOS 7及以上版本如何安装Docker,网上的教程一大堆,这里就不再赘述了。但是目前应该还有很多公司在使用CentOS 6.X(我所在的公司就是),那有没有不升级内核版本,就可以直接安装的Docker呢?答案是有的,Docker之前还是有一个版本可以支持CentOS 6.X的,那就是docker-engine,但是只支持最新的几个版本。本文就CentOS 6.10不升级内核安装Docker作一个介绍。

一、下载rpm包

官方网站下载地址:https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm 阿里云镜像下载地址:https://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/6/Packages/docker-engine-1.7.1-1.el6.x86_64.rpm 由于官方网站是在国外,可能会由于网络原因下载慢或者下载不了,所以可以直接在阿里云镜像下载。

二、安装

下载好安装包了,安装就很简单了。

1rpm -ivh docker-engine-1.7.1-1.el6.x86_64.rpm

如果想省事一些,可以直接使用下载地址进行安装:

1yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm

或者

1yum install https://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/6/Packages/docker-engine-1.7.1-1.el6.x86_64.rpm

注意:

  • 安装时需要使用root权限,如果不是root账号,需要在前面加上sudo来执行。
  • 所有docker相关命令的执行都需要root权限,如果不是root账号,需要在前面加上sudo来执行。
 1[witton@localhost 桌面]$ sudo yum install https://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/6/Packages/docker-engine-1.7.1-1.el6.x86_64.rpm 
 2[sudo] password for witton: 
 3已加载插件:fastestmirror, refresh-packagekit, security
 4设置安装进程
 5诊断 docker-engine-1.7.1-1.el6.x86_64.rpm: docker-engine-1.7.1-1.el6.x86_64
 6docker-engine-1.7.1-1.el6.x86_64.rpm 将被安装
 7Determining fastest mirrors
 8 * base: mirrors.aliyun.com
 9 * extras: mirrors.aliyun.com
10 * updates: mirrors.aliyun.com
11http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
12尝试其他镜像。
13To address this issue please refer to the below wiki article 
14
15https://wiki.centos.org/yum-errors
16
17If above article doesn't help to resolve this issue please use https://bugs.centos.org/.
18
19http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
20尝试其他镜像。
21http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.cloud.aliyuncs.com'"
22尝试其他镜像。
23code                                                     | 3.0 kB     00:00     
24code/primary_db                                          | 1.3 MB     00:01     
25http://mirrors.aliyun.com/centos/6/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
26尝试其他镜像。
27http://mirrors.aliyuncs.com/centos/6/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
28尝试其他镜像。
29http://mirrors.cloud.aliyuncs.com/centos/6/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.cloud.aliyuncs.com'"
30尝试其他镜像。
31http://mirrors.aliyun.com/centos/6/updates/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
32尝试其他镜像。
33http://mirrors.aliyuncs.com/centos/6/updates/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
34尝试其他镜像。
35http://mirrors.cloud.aliyuncs.com/centos/6/updates/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.cloud.aliyuncs.com'"
36尝试其他镜像。
37解决依赖关系
38--> 执行事务检查
39---> Package docker-engine.x86_64 0:1.7.1-1.el6 will be 安装
40--> 完成依赖关系计算
41
42依赖关系解决
43
44================================================================================
45 软件包         架构    版本           仓库                                大小
46================================================================================
47正在安装:
48 docker-engine  x86_64  1.7.1-1.el6    /docker-engine-1.7.1-1.el6.x86_64   19 M
49
50事务概要
51================================================================================
52Install       1 Package(s)
53
54总文件大小:19 M
55Installed size: 19 M
56确定吗?[y/N]:y
57下载软件包:
58运行 rpm_check_debug 
59执行事务测试
60事务测试成功
61执行事务
62Warning: RPMDB altered outside of yum.
63** Found 13 pre-existing rpmdb problem(s), 'yum check' output follows:
64gcc-10.2.0-1.x86_64 is a duplicate with gcc-4.4.7-23.el6.x86_64
65git-2.29.2-1.x86_64 has missing requires of perl(DBI)
66git-2.29.2-1.x86_64 has missing requires of perl(SVN::Core)
67git-2.29.2-1.x86_64 has missing requires of perl(SVN::Delta)
68git-2.29.2-1.x86_64 has missing requires of perl(SVN::Ra)
69git-2.29.2-1.x86_64 has missing requires of perl(Time::HiRes)
70git-2.29.2-1.x86_64 has missing requires of perl(YAML::Any)
71llvm-9.0.0-1.x86_64 has missing requires of libpython3.5m.so.1.0()(64bit)
72llvm-9.0.0-1.x86_64 has missing requires of python(abi) = ('0', '3.5', None)
73openssl-1.1.1g-1.x86_64 is a duplicate with openssl-1.0.1e-58.el6_10.x86_64
74openssl-1.1.1g-1.x86_64 has missing requires of perl(WWW::Curl::Easy)
75python-3.9.0-1.x86_64 is a duplicate with python-2.6.6-68.el6_10.x86_64
76python-3.9.0-1.x86_64 has missing requires of /usr/local/bin/python
77  正在安装   : docker-engine-1.7.1-1.el6.x86_64                             1/1 
78  Verifying  : docker-engine-1.7.1-1.el6.x86_64                             1/1 
79
80已安装:
81  docker-engine.x86_64 0:1.7.1-1.el6                                            
82
83完毕!

这是我的安装记录,前面有一些错误可以不用管它(因为我的更新源原来设置的是阿里云,但是现在阿里云已经去掉了CentOS 6.X的镜像了,所以会报错),可以看到最后是安装成功了。

为了防止报错,建议还是采用先下载安装包,再使用rpm -ivh的方式进行安装

三、测试

  • 查看版本号 安装完成后,可以通过docker version来查看版本号:
 1[witton@localhost 桌面]$ sudo docker version
 2[sudo] password for witton: 
 3Client version: 1.7.1
 4Client API version: 1.19
 5Go version (client): go1.4.2
 6Git commit (client): 786b29d
 7OS/Arch (client): linux/amd64
 8Server version: 1.7.1
 9Server API version: 1.19
10Go version (server): go1.4.2
11Git commit (server): 786b29d
12OS/Arch (server): linux/amd64
  • 启动docker服务 使用service docker start来启动服务:
1[witton@localhost 桌面]$ sudo service docker start
2Starting docker:	                                   [确定]
  • 拉取docker镜像 为了测试,我们以拉取mysql 5.6为例,使用命令docker pull mysql:5.6拉取。
 1[witton@localhost 桌面]$ sudo docker pull mysql:5.6
 25.6: Pulling from mysql
 363ae8ab270fe: Pull complete 
 43bfa3565bd8f: Pull complete 
 5572771b861e4: Pull complete 
 60d0eacc8e3c7: Pull complete 
 7a4748865b4a2: Pull complete 
 839ea54790f0a: Pull complete 
 9b599b4d1d2b1: Pull complete 
10f38555590848: Pull complete 
114515ac1341b3: Pull complete 
12e50382504ad5: Pull complete 
13be642a0affca: Pull complete 
14bab5b21ffc28: Pull complete 
15b46ddca5d859: Pull complete 
16fb62ad063f8b: Pull complete 
17e881d90c7580: Pull complete 
184a6ddf641046: Pull complete 
1949afeae5d217: Pull complete 
20073dce8c6ba3: Pull complete 
21b26b0dfb042e: Pull complete 
22Digest: sha256:81dd57ba2d55fcd26a2dc8b1f4a5b70523f0e7c440d9edbda69e963be5997a3b
23Status: Downloaded newer image for mysql:5.6
  • 查看本地镜像
1[witton@localhost 桌面]$ sudo docker images
2[sudo] password for witton: 
3REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
4mysql               5.6                 b26b0dfb042e        3 weeks ago         302.5 MB

我们可以看到已经有mysql 5.6的镜像了。

  • 启动docker容器 使用命令
1docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6

来启动容器, 参数说明:

  • -i: 交互式操作
  • -t: 终端
  • -d:后台方式运行
  • –name指定容器的名字
  • -p 3306:3306 指定容器与宿主机的端口映射,即把容器中的3306端口映射到宿主机的3306端口,注意,前面的3306为宿主机端口,后面的3306是容器中的端口
  • -e MYSQL_ROOT_PASSWORD=123456 指定mysql的root密码为123456
  • mysql:5.6指定镜像的名字和版本
1[witton@localhost 桌面]$ sudo docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
25063574a1a4cb652094420eff5c35029e3e4e1afee2a5b418bd8649fcfea99af

运行成功后,会返回一串16进制数据,这个是容器的完整ID。

  • 使用容器

在使用容器之前,我们需要使用到容器的ID,由于创建的时候返回的容器ID太长,使用不便,所以docker允许使用一串短的ID来表示。

使用docker ps命令来查看当前运行的容器:

1[witton@localhost 桌面]$ sudo docker ps
2CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
35063574a1a4c        mysql:5.6           "docker-entrypoint.s   7 minutes ago       Up 7 minutes        0.0.0.0:3306->3306/tcp   mysql-test 

前面的短ID就是后面需要用到的ID。

使用命令:

1sudo docker exec -it 5063574a1a4c /bin/bash

来进入容器的bash环境,这时会提示:

1root@5063574a1a4c:/

就进入容器内了,我们执行连接mysql,在刚才的提示符中输入:

1mysql -uroot -p123456

即可进入mysql控制台了。完整输入输出如下:

 1[witton@localhost 桌面]$ sudo docker exec -it 5063574a1a4c /bin/bash
 2root@5063574a1a4c:/# mysql -uroot -p123456
 3Warning: Using a password on the command line interface can be insecure.
 4Welcome to the MySQL monitor.  Commands end with ; or \g.
 5Your MySQL connection id is 2
 6Server version: 5.6.51 MySQL Community Server (GPL)
 7
 8Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
 9
10Oracle is a registered trademark of Oracle Corporation and/or its
11affiliates. Other names may be trademarks of their respective
12owners.
13
14Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
15
16mysql> show databases;
17+--------------------+
18| Database           |
19+--------------------+
20| information_schema |
21| mysql              |
22| performance_schema |
23+--------------------+
243 rows in set (0.01 sec)
25
26mysql> 

说明我们的Docker是完全可以正常使用的。

转载请注明出处: https://blog.csdn.net/witton/article/details/119710481

祝好,欢迎关注与点赞!