ubuntu和centos安装docker

本文详细介绍了在Ubuntu和CentOS系统上安装Docker及Docker Compose的过程,包括卸载旧版本、安装必要工具、配置加速器等关键步骤,并针对常见问题提供了解决方案。

 

 一. UBUNTU系统上

 

1. 卸载旧版本(新系统不用执行)

sudo apt-get remove docker docker-engine docker.io
 
 

2. 安装docker

step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
 
step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -   #如果这个不行用下面的
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
 
Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
#sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
 
Step 4: 更新并安装Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce
 
 
另外一种安装方式
http://blog.youkuaiyun.com/change_on/article/details/76690934
 
 
 

二. CENTOS安装docker

 

1. centos6安装docker1.71很简单, 如下,但是不支持docker-compose,因为docker版本太低
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  ---这样方式安装的是docker-engine,启动的时候有时候会出错。
或者
yum install docker-io -y  --还是这种方式稳些
 
2. 在centos6上跑docker和docker-compose
要跑docker-compose必要要求docker版本在1.9以上,官方要求docker需要运行在centos7以上,内核要3.1以上,并且现在在centos6版本上docker版本最新的只有1.7的
 
1)不升级内核的方法:可参考 http://blog.youkuaiyun.com/kinginblue/article/details/73527832, 这个比较麻烦,没验证
 
2)升级内核,然后安装docker 1.9的方法:已经过验证,可行
 
 首先升级内核,否则docker会很卡
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org  #导入public key
rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm  #安装ELRepo到centos
yum --enablerepo=elrepo-kernel install kernel-ml -y  #安装kernel,后缀ml是最新版,lt事稳定版
vim /etc/grub.conf  修改第一行为default=0   #修改grub引导顺序,一般新安装的内核在第一个位置,设置default=0,表示启动新内核

最后重启系统即可
 
 
 升级完后装docker 1.9
yum install epel-release -y
yum
install docker-io -y #安装docker1.7.1 curl -sSL -O https://get.docker.com/builds/Linux/x86_64/docker-1.9.1 #下载1.9.1,我是用香港aliyun服务器下载的,国内的好像不行
# wget -c https://get.docker.com/builds/Linux/x86_64/docker-1.10.3 下载docker-1.10版的地址,但是在6上貌似不可用
chmod +x docker-1.9.1
mv docker-1.9.1 /usr/bin/docker  #替换
service docker restart
docker version   #查看版本

 

 

3. centos7上安装docker
参考:http://blog.youkuaiyun.com/yuan_cheerleaders/article/details/51480077

Uninstall old versions 

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

Install Docker CE 

Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.

$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

Install the latest version of Docker CE

$ sudo yum install docker-ce

Start Docker.

$ sudo systemctl start docker

Verify that docker is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Uninstall Docker CE

Uninstall the Docker package

$ sudo yum remove docker-ce

 Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes

$ sudo rm -rf /var/lib/docker
 
 
4. 卸载docker
yum list installed | grep docker  ---查看安装的docker版本,
yum remove ...
rm-rf /var/lib/docker
 
 
   

三. 安装docker-compose

 
# 通过镜像安装docker-compose
curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
 
docker 18.09对于的docker-compose版本1.18.0,可以把下面gitlhub上的版本号改成对于的版本号
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
 
# docker-compose 命令增强

 

  

四. 使用加速器

Daocloud中的docker加速器---适用于ubuntu 14, centos 6以上版本
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://9c10a7d1.m.daocloud.io    #需要注册daocloud
 
重启守护进程:
service docker restart
Ok,现在再pull则速度很满意。
 
 
 
五. 常见问题总结
 
1. centos7中安装docker,docker-compose文件不能正常启动
问题1. curl下载https开头的地址  docker-compose 文件时出现 Peer reports incompatible or unsupported protocol version
解决方式:yum update nss curl # nss为名称解析和认证服务 curl为网络请求库
 
问题2:docker安装成功,启动报错
解决方法:yum upudate xfsprogs ,之后重启docker
 
 
 
 

 centos6上装docker参考:

http://blog.youkuaiyun.com/jeffleo/article/details/70904150    

http://www.senra.me/centos6-install-new-docker-191-or-113/    #编译方法升级到1.13版,经测试不靠谱

 
 
 
 
 
 

转载于:https://www.cnblogs.com/regit/p/8268948.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值