ubuntu和centos安装docker

 欧拉系统离线安装docker

https://blog.csdn.net/feifeiyechuan/article/details/129314938

 一. 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

 

安装指定版本

(k8s中docker版本太新会报警告,目前19.05前安全)

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 19.03 | head -1 | awk '{print $3}')
cat > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}

 

卸载docker

查看所有apt-get安装的列表
dpkg -l

卸载docker
apt-get --purge remove docker-ce
apt-get remove docker docker-engine docker.io containerd runc (第一条报错再加这一条)

 

 
 
 
 
另外一种安装方式
http://blog.csdn.net/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.csdn.net/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.csdn.net/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

 
# 官网下载地址
https://github.com/docker/compose/releases

 

例如下载1.8.0版本的
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.csdn.net/jeffleo/article/details/70904150    

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

 
 
 
 
 
 
posted @ 2018-01-11 16:08  坚强的小蚂蚁  阅读(666)  评论(0编辑  收藏  举报