CentOS 6.10不升级内核安装Docker

目前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
由于官方网站是在国外,可能会由于网络原因下载慢或者下载不了,所以可以直接在阿里云镜像下载。

二、安装

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

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

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

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

或者

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

注意:

  1. 安装时需要使用root权限,如果不是root账号,需要在前面加上sudo来执行。
  2. 所有docker相关命令的执行都需要root权限,如果不是root账号,需要在前面加上sudo来执行。
[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 
[sudo] password for witton: 
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
诊断 docker-engine-1.7.1-1.el6.x86_64.rpm: docker-engine-1.7.1-1.el6.x86_64
docker-engine-1.7.1-1.el6.x86_64.rpm 将被安装
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
尝试其他镜像。
To address this issue please refer to the below wiki article 

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
尝试其他镜像。
http://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'"
尝试其他镜像。
code                                                     | 3.0 kB     00:00     
code/primary_db                                          | 1.3 MB     00:01     
http://mirrors.aliyun.com/centos/6/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
尝试其他镜像。
http://mirrors.aliyuncs.com/centos/6/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
尝试其他镜像。
http://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'"
尝试其他镜像。
http://mirrors.aliyun.com/centos/6/updates/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
尝试其他镜像。
http://mirrors.aliyuncs.com/centos/6/updates/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
尝试其他镜像。
http://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'"
尝试其他镜像。
解决依赖关系
--> 执行事务检查
---> Package docker-engine.x86_64 0:1.7.1-1.el6 will be 安装
--> 完成依赖关系计算

依赖关系解决

================================================================================
 软件包         架构    版本           仓库                                大小
================================================================================
正在安装:
 docker-engine  x86_64  1.7.1-1.el6    /docker-engine-1.7.1-1.el6.x86_64   19 M

事务概要
================================================================================
Install       1 Package(s)

总文件大小:19 M
Installed size: 19 M
确定吗?[y/N]:y
下载软件包:
运行 rpm_check_debug 
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
** Found 13 pre-existing rpmdb problem(s), 'yum check' output follows:
gcc-10.2.0-1.x86_64 is a duplicate with gcc-4.4.7-23.el6.x86_64
git-2.29.2-1.x86_64 has missing requires of perl(DBI)
git-2.29.2-1.x86_64 has missing requires of perl(SVN::Core)
git-2.29.2-1.x86_64 has missing requires of perl(SVN::Delta)
git-2.29.2-1.x86_64 has missing requires of perl(SVN::Ra)
git-2.29.2-1.x86_64 has missing requires of perl(Time::HiRes)
git-2.29.2-1.x86_64 has missing requires of perl(YAML::Any)
llvm-9.0.0-1.x86_64 has missing requires of libpython3.5m.so.1.0()(64bit)
llvm-9.0.0-1.x86_64 has missing requires of python(abi) = ('0', '3.5', None)
openssl-1.1.1g-1.x86_64 is a duplicate with openssl-1.0.1e-58.el6_10.x86_64
openssl-1.1.1g-1.x86_64 has missing requires of perl(WWW::Curl::Easy)
python-3.9.0-1.x86_64 is a duplicate with python-2.6.6-68.el6_10.x86_64
python-3.9.0-1.x86_64 has missing requires of /usr/local/bin/python
  正在安装   : docker-engine-1.7.1-1.el6.x86_64                             1/1 
  Verifying  : docker-engine-1.7.1-1.el6.x86_64                             1/1 

已安装:
  docker-engine.x86_64 0:1.7.1-1.el6                                            

完毕!

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

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

三、测试

  1. 查看版本号
    安装完成后,可以通过docker version来查看版本号:
[witton@localhost 桌面]$ sudo docker version
[sudo] password for witton: 
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
  1. 启动docker服务
    使用service docker start来启动服务:
[witton@localhost 桌面]$ sudo service docker start
Starting docker:	                                   [确定]

  1. 拉取docker镜像
    为了测试,我们以拉取mysql 5.6为例,使用命令docker pull mysql:5.6拉取。
[witton@localhost 桌面]$ sudo docker pull mysql:5.6
5.6: Pulling from mysql
63ae8ab270fe: Pull complete 
3bfa3565bd8f: Pull complete 
572771b861e4: Pull complete 
0d0eacc8e3c7: Pull complete 
a4748865b4a2: Pull complete 
39ea54790f0a: Pull complete 
b599b4d1d2b1: Pull complete 
f38555590848: Pull complete 
4515ac1341b3: Pull complete 
e50382504ad5: Pull complete 
be642a0affca: Pull complete 
bab5b21ffc28: Pull complete 
b46ddca5d859: Pull complete 
fb62ad063f8b: Pull complete 
e881d90c7580: Pull complete 
4a6ddf641046: Pull complete 
49afeae5d217: Pull complete 
073dce8c6ba3: Pull complete 
b26b0dfb042e: Pull complete 
Digest: sha256:81dd57ba2d55fcd26a2dc8b1f4a5b70523f0e7c440d9edbda69e963be5997a3b
Status: Downloaded newer image for mysql:5.6
  1. 查看本地镜像
[witton@localhost 桌面]$ sudo docker images
[sudo] password for witton: 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
mysql               5.6                 b26b0dfb042e        3 weeks ago         302.5 MB

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

  1. 启动docker容器
    使用命令
docker 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指定镜像的名字和版本
[witton@localhost 桌面]$ sudo docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
5063574a1a4cb652094420eff5c35029e3e4e1afee2a5b418bd8649fcfea99af

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

  1. 使用容器

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

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

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

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

使用命令:

sudo docker exec -it 5063574a1a4c /bin/bash

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

root@5063574a1a4c:/

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

mysql -uroot -p123456

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

[witton@localhost 桌面]$ sudo docker exec -it 5063574a1a4c /bin/bash
root@5063574a1a4c:/# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

mysql> 

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

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

祝好,欢迎关注与点赞!

Guess you like

Origin blog.csdn.net/witton/article/details/119710481