docker-ce安装

一、yum安装指定版本docker-ce

docker RPM包官方网址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
docker tar包官方网址:https://download.docker.com/linux/static/stable/x86_64/

1、配置本地以及网络yum源

#配置本地yum源
cd /etc/yum.repos.d/
#判断光盘是否挂载
[ -d /media/cdrom ] || mkdir /media/cdrom
mount | grep  sr0 &> /dev/null
[ $? -eq 0 ] || mount /dev/sr0 /media/cdrom
echo "光盘已挂载"
#安装使用包
yum -y install wget net-tools psmisc gcc gcc-c++ make unzip which
mv CentOS-Base.repo CentOS-Base.repo.bak
#配置网络yum源
[ -f CentOS7-Base-163.repo ] || wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[ -f Centos-7.repo ] || wget http://mirrors.aliyun.com/repo/Centos-7.repo
[ -f epel-testing.repo ] || wget http://mirrors.aliyun.com/repo/epel-testing.repo
[ -f epel-7.repo ] || wget http://mirrors.aliyun.com/repo/epel-7.repo
[ -f epel.repo ] || wget http://mirrors.aliyun.com/repo/epel.repo
yum clean all && yum makecache
yum install -y yum-utils

2、配置docker源以及yum安装

-卸载旧版本

yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

-安装所需软件包

#yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper 存储驱动程序
yum install -y device-mapper-persistent-data  lvm2

-配置docker源

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum makecache

-查询可安装版本

yum list docker-ce --showduplicates | sort -r

-安装docker-ce-19.03.5

yum -y install docker-ce-19.03.5 docker-ce-cli-19.03.5 containerd.io

-启动docker

systemctl start docker

-检查版本

docker version

Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:25:41 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:24:18 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.18.0
GitCommit: fec3683

二、二进制安装docker

1.下载docker tar包

wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.3.tgz

2.解压

tar xf docker-19.03.3.tgz
cd docker
ll ./
[root@localhost docker]# ll
总用量 204696
-rwxr-xr-x 1 cka cka 34625816 10月 8 2019 containerd
-rwxr-xr-x 1 cka cka 6116160 10月 8 2019 containerd-shim
-rwxr-xr-x 1 cka cka 18850136 10月 8 2019 ctr
-rwxr-xr-x 1 cka cka 65641747 10月 8 2019 docker
-rwxr-xr-x 1 cka cka 72067152 10月 8 2019 dockerd
-rwxr-xr-x 1 cka cka 764144 10月 8 2019 docker-init
-rwxr-xr-x 1 cka cka 2877369 10月 8 2019 docker-proxy
-rwxr-xr-x 1 cka cka 8649800 10月 8 2019 runc

3.拷贝命令到/usr/bin/

cp docker/* /usr/bin/
PS:因为启动文件中的命令取自/usr/bin

**查看docker版本**
**docker version**
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.3
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        a872fc2f86
 Built:             Tue Oct  8 00:54:52 2019
 OS/Arch:           linux/amd64
 Experimental:      false
**Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?**
表示找不到docker.sock,docker服务未启动

4.准备service启动文件

vim /lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target

5.启动docker

chmod +x /lib/systemd/system/docker.service
systemctl daemon-reload //重载systemd下 xxx.service文件
systemctl start docker //启动Docker
systemctl enable docker.service //设置开机自启

-查看版本

[root@localhost ~] docker version
Client: Docker Engine - Community
 Version:           19.03.3
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        a872fc2f86
 Built:             Tue Oct  8 00:54:52 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.3
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.10
  Git commit:       a872fc2f86
  Built:            Tue Oct  8 01:01:20 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

二进制安装脚本

#!/bin/bash
set -x
tar_name=docker-19.03.3.tgz
#var
unamer=`uname -r |cut -d'.' -f1-2`
 
#kernel 3.10+
if [[ $unamer -lt 3.10 ]];then
    echo "the linux kernel too lower" && exit 8
fi
 
#setup
tar xf  $tar_name && mv docker/* /usr/bin/ && rm -rf docker*
 
#systemd config
cat >/lib/systemd/system/docker.service <<-EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target
EOF
 
#start
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload && systemctl start docker && systemctl enable docker.service   
 
#look docker.service
systemctl status docker && docker -v

更改工作目录

更改工作目录以及仓库

docker info |grep "Docker Root Dir"

cat << eof > /etc/docker/daemon.json

{

"data-root": "/data/docker",

"registry-mirrors": ["[<u>http://hub-mirror.c.163.com</u>](http://hub-mirror.c.163.com/)"],     国内镜像源

"insecure-registries": ["docker.erick.com:5000"]  私有仓库

}

eof

systemctl restart docker
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,527评论 5 470
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,314评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,535评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,006评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,961评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,220评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,664评论 3 392
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,351评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,481评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,397评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,443评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,123评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,713评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,801评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,010评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,494评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,075评论 2 341

推荐阅读更多精彩内容