docker安装(离线一键安装、yum源安装、rpm包安装、二进制文件安装等)

@[toc]

1. 离线一键部署(推荐)

  • 包含:
    1) docker v1.19
    2)docker-compose v1.24.0

  • 适用环境
    centos 7
    Ubuntu 18 +

  • 下载地址
    >>> CSDN 下载连接

  • 安装方式
    执行部署包中的compose_install.sh脚本即可。

2. 阿里云yum源安装

2.1 卸载旧版

# yum remove docker \
docker-common \ 
docker-selinux \ 
docker-engine 

有得文档上选择卸载组件比较多:

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

2.2 安装依赖包

# yum install -y yum-utils device-mapper-persistent-data lvm2

2.3 yum源

2.3.1 添加yum源

# yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

2.3.2 更新yum源

说明:非必要

yum-config-manager --enable docker-ce-edge

2.4 安装

1)清除缓存

yum makecache fast

2)安装

# yum install docker-ce -y

2.5 启动和添加开机启动项

(略)

3. 官方源安装(择版本选择)

3.1 卸载老版本的Docker

说明:同上

3.2 官方yum源

说明:要启用哪个版本的源就将其下的enable值设置为1

# cat /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://download.docker.com/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://download.docker.com/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

3.3 查看可用版本

# yum list docker-ce --showduplicates|grep "^doc"|sort -r
docker-ce.x86_64            18.06.1.ce-3.el7                  docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                  docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable

3.4 安装指定版本

说明:以docker-ce-18.06.0.ce-3.el7为例

# yum -y install docker-ce-18.06.0.ce-3.el7

3.5 启动docker 设置开机启动

(略)

4. 其他离线安装方式

4.1 rpm安装

  • 安装包
    附件“离线安装包”目录中

  • 安装

# rpm -vih docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm 
# rpm -vih docker-ce-17.03.3.ce-1.el7.x86_64.rpm4.rpm 
  • 启动并设置开机启动(略)

4.2 yum 安装

准备好yum用的rpm包,拷贝到服务器,执行

yum localinstall *.rpm

4.3 二进制文件安装

  • 官网下载
    https://download.docker.com/linux/static/stable/x86_64/

  • 解压缩

tar xf docker-xxxxx.tgz
  • 拷贝二进制文件
cp docker/* /usr/bin/
  • docker注册为server

创建 /etc/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

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
  • 给执行权限
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload
  • 启动并设置开机启动
    (略)

你可能感兴趣的:(docker安装(离线一键安装、yum源安装、rpm包安装、二进制文件安装等))