阿里云cenos 6.5 模板上安装 docker

本章将介绍在阿里云的 Centos6.5 模板上安装 Docker 以及在 Ubuntu 14.04 模板上安装 Docker 的过程

Centos 6.5 模板上使用Docker

首先,通过 ssh 登陆阿里云的服务器,查看系统版本号以及内核版本。

Welcome to aliyun Elastic Compute Service!
# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.5 (Final)
Release:        6.5
Codename:       Final
# uname -a
Linux xxxxxxx 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

升级内核

因为 Docker 推荐使用 3.8 以上内核,所以我们选择使用 YUM 方式来升级内核。

导入 KEY ,安装软件源。在 YUM 的 ELRepo 源中,有 mainline(3.13.1)、long-term(3.10.28)这 2 个内核版本,考虑到 long-term 更稳定,会长期更新,所以选择这个版本。

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# yum --enablerepo=elrepo-kernel install kernel-lt -y
Loaded plugins: security
base                                                                                                                          | 3.7 kB     00:00
base/primary_db                                                                                                               | 4.6 MB     00:00
elrepo                                                                                                                        | 2.9 kB     00:00
elrepo/primary_db                                                                                                             | 709 kB     00:46
elrepo-kernel                                                                                                                 | 2.9 kB     00:00
elrepo-kernel/primary_db                                                                                                      |  20 kB     00:01
epel                                                                                                                          | 4.4 kB     00:00
epel/primary_db                                                                                                               | 6.3 MB     00:01
extras                                                                                                                        | 3.4 kB     00:00
extras/primary_db                                                                                                             |  29 kB     00:00
updates                                                                                                                       | 3.4 kB     00:00
updates/primary_db                                                                                                            | 181 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package kernel-lt.x86_64 0:3.10.59-1.el6.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================
 Package                         Arch                         Version                                      Repository                           Size
=====================================================================================================================================================
Installing:
 kernel-lt                       x86_64                       3.10.59-1.el6.elrepo                         elrepo-kernel                        33 M

Transaction Summary
=====================================================================================================================================================
Install       1 Package(s)

Total download size: 33 M
Installed size: 153 M
Downloading Packages:
kernel-lt-3.10.59-1.el6.elrepo.x86_64.rpm                                                                                     |  33 MB     28:58
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : kernel-lt-3.10.59-1.el6.elrepo.x86_64                                                                                             1/1
  Verifying  : kernel-lt-3.10.59-1.el6.elrepo.x86_64                                                                                             1/1

Installed:
  kernel-lt.x86_64 0:3.10.59-1.el6.elrepo

Complete!

vi /etc/grub.conf 修改默认的启动内核,新安装的内核一般在第一个,这里把default = 1 改为 default = 0 就好了。

default=1
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.59-1.el6.elrepo.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-3.10.59-1.el6.elrepo.x86_64 ro root=UUID=94e4e384-0ace-437f-bc96-057dd64f42ee rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /boot/initramfs-3.10.59-1.el6.elrepo.x86_64.img
title CentOS (2.6.32-431.23.3.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-431.23.3.el6.x86_64 ro root=UUID=94e4e384-0ace-437f-bc96-057dd64f42ee rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /boot/initramfs-2.6.32-431.23.3.el6.x86_64.img
~

重启云主机,查看内核是否升级成功。

# uname -a
Linux xxxxxxx 3.10.59-1.el6.elrepo.x86_64 #1 SMP Thu Oct 30 23:46:31 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux

安装 Docker

安装软件源,安装 Docker 软件。

# yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
# yum install docker-io

启动 Docker

安装平常的方法启动 Docker 之后,发现仍然提示有问题。

# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:                                           [  OK  ]
# docker version
Client version: 1.2.0
Client API version: 1.14
Go version (client): go1.3.3
Git commit (client): fa7b24f/1.2.0
OS/Arch (client): linux/amd64
2014/11/05 21:03:08 Cannot connect to the Docker daemon. Is ‘docker -d‘ running on this host?

使用 docker -d 来查看详细的启动过程。

# docker -d
2014/11/05 21:10:56 docker daemon: 1.2.0 fa7b24f/1.2.0; execdriver: native; graphdriver:
[40a2dcc2] +job serveapi(unix:///var/run/docker.sock)
[info] Listening for HTTP on unix (/var/run/docker.sock)
[40a2dcc2] +job init_networkdriver()
[40a2dcc2.init_networkdriver()] creating new bridge for docker0
Could not find a free IP address range for interface ‘docker0‘. Please configure its address manually and run ‘docker -b docker0‘
[40a2dcc2] -job init_networkdriver() = ERR (1)
2014/11/05 21:10:56 Could not find a free IP address range for interface ‘docker0‘. Please configure its address manually and run ‘docker -b docker0‘

提示我们没有空余 ip 分配给 docker0 了。

那我们就使用 --bip 参数来手工分配给 ip 地址。比如:

# docker --bip=192.168.100.1/24 -d &
[2] 2388
[[email protected] ~]# 2014/11/05 21:16:55 docker daemon: 1.2.0 fa7b24f/1.2.0; execdriver: native; graphdriver:
[dc6906e7] +job serveapi(unix:///var/run/docker.sock)
[info] Listening for HTTP on unix (/var/run/docker.sock)
[dc6906e7] +job init_networkdriver()
[dc6906e7] -job init_networkdriver() = OK (0)
2014/11/05 21:16:55 WARNING: Your kernel does not support cgroup swap limit.
[info] Loading containers:
[info] : done.
[dc6906e7] +job acceptconnections()
[dc6906e7] -job acceptconnections() = OK (0)

这里提示警告 Your kernel does not support cgroup swap limit.,我们可以使用 lxc-checkconfig 来检查。

# lxc-checkconfig
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-3.10.59-1.el6.elrepo.x86_64
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: missing
Network namespace: enabled
Multiple /dev/pts instances: enabled

--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled

Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

可以看到 Control groups 项目都是支持的,所以我们暂时忽略这个告警。

测试使用

由于 Aliyun 的网络直接 pull 官方镜像也不是很稳定,这里推荐使用Dockerpool 官方网站的标准ubuntu镜像来测试。

下载镜像,重新标记镜像。

# docker pull dl.dockerpool.com:5000/ubuntu:14.04
# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
dl.dockerpool.com:5000/ubuntu   latest              5506de2b643b        12 days ago         197.8 MB
# docker tag 550 ubuntu
# docker rmi dl.dockerpool.com:5000/ubuntu
[dc6906e7] +job image_delete(dl.dockerpool.com:5000/ubuntu)
[dc6906e7] +job log(untag, 5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5, )
[dc6906e7] -job log(untag, 5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5, ) = OK (0)
[dc6906e7] -job image_delete(dl.dockerpool.com:5000/ubuntu) = OK (0)
Untagged: dl.dockerpool.com:5000/ubuntu:latest

启动容器,并测试网络。

# docker run -ti ubuntu
[email protected]66ff9a55a4f5:/# ping www.dockerpool.com
PING www.dockerpool.com (xxx.xxx.xxx.xxx) 56(84) bytes of data.
^C64 bytes from 203.195.193.251: icmp_seq=1 ttl=47 time=31.4 ms
时间: 2024-08-03 14:24:31

阿里云cenos 6.5 模板上安装 docker的相关文章

阿里云 ubuntu 14.04 模板上安装 docker

ubuntu 14.04 的内核是 3.13 ,所以内核不用升级. 安装步骤如下: # apt-get update # apt-get install apt-transport-https # apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 # bash -c "echo deb https://get.docker.io/ub

在阿里云主机的Debian操作系统上安装Docker

## 下面命令都是以root用户执行 ## 查看内核版本 uname -a # Debian 3.2.0-4 x86_64 ## 版本太低了 < 3.8 ## 参照 http://docs.docker.com/installation/debian/ 升级内核 deb http://http.debian.net/debian wheezy-backports main apt-get update apt-get install -t wheezy-backports linux-image

尝试在阿里云的Linux服务器器上安装拥有图形界面的Pycharm

在Linux服务器上跑Python项目发现每次从本地上传文件太过麻烦,于是打算在服务器上安装Pycharm直接写Pycharm代码.   去Pycharm的官网下载Linux版本(支持正版于是我下载了社区版) 在服务器上建立一个名为Pychar文件. 通过winSCP软件吧刚刚下载好的Linux版本的Pycharm上传到服务器的Pycharm文件夹 解压文件 tar xfz pycharm-community-2019.3.3.tar.gz 然后打开Pycharm文件下的bin 输入命令运许bi

阿里云在Nginx/Tengine服务器上安装证书和在IIS服务器上安装SSL证书

在Nginx/Tengine服务器上安装证书 https://help.aliyun.com/document_detail/98728.html?spm=5176.2020520163.0.0.3c3856a7A8zZ8s 在IIS服务器上安装SSL证书 https://help.aliyun.com/document_detail/98729.html?spm=5176.2020520163.0.0.3c3856a7A8zZ8s 原文地址:https://www.cnblogs.com/pa

阿里云Ubuntu 12.4 64位 安装docker

最近大家都在说docker,索性自己阿里云买了台ubuntu完,这里需要注意的是,docker的官方文档中有提到,docker目前只对64的系统有支持. 所以这里我选择的是ubuntu 12.04 64位. 由于linux容器的bug,docker在linux的kernel3.8上运行最佳. 看下我们的ubuntu版本命令: [email protected]:~# cat /etc/issue Ubuntu 12.04.5 LTS \n \l 再来看下内核,命令: [email protect

在阿里云的vps上安装docker

在阿里云的vps上安装docker后不能正常启动,查看docker日志发现有如下错误: Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0' time="2015-03-08T17:50:30+08:00" level="info" msg="-job

在阿里云Ubuntu 14.04 Linux服务器上安装docker

参考 How To Install and Use Docker: Getting Started 这篇最靠谱的文档在阿里云 Ubuntu  14.04 服务器上成功安装 docker . 1)更新 apt 的安装包列表 sudo apt-get update 2)升级所有已安装的包 sudo apt-get -y upgrade 3)添加 apt 验证密钥 sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E8

CentOS 6.5上安装docker与docker对中文字符集的支持

一.CentOS 6.5上安装docker 在CentOS 6.5 还不能够直接通过yum install -y docker 来安装docker服务 在一些文档中有看到说是因为内核太低的原因导致的,因为docker至少要做3.8以上的版本才能安装, 但是我发现其实并不需要升级内核就可以实现docker的安装不过,也有可能我的安装存在偶然性, 但是我还是记录一下,以防日后忘记. 1.先查看下你的系统内核是多少 # uname -r 2.6.32-431.el6.x86_64 我的是CentOS

在 Mac OS X 上安装 Docker(转)

http://www.oschina.net/translate/installing-docker-on-mac-os-x?print 在 Mac OS X 上安装 Docker 注意:Docker支持Mac OS X 10.6 "Snow Leopard" 及其以上版本. Docker引擎使用了Linux内核特定的特性,所以要让它运行在OS X上我们需要用一个轻量型的虚拟机(vm).用OS X的Docker客户端来控制虚拟Docker来构建,运行以及管理Docker容器. 为了使过