当前位置:   article > 正文

Docker安装的三种方式

docker安装

Docker安装的三种方式

1、二进制方式安装

下载解压:

cd /opt
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.1.tgz
tar -xf docker-20.10.1.tgz
mv docker/* /usr/bin/
  • 1
  • 2
  • 3
  • 4

配置镜像加速:

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

作为服务启动:

cat > /usr/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
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
#TasksMax=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

启动:

systemctl daemon-reload
systemctl start docker
systemctl enable docker
systemctl status docker
  • 1
  • 2
  • 3
  • 4

2、rpm方式安装docker

下载地址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

mkdir -p /opt/docker_rpm
cd /opt/docker_rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el7.x86_64.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-20.10.1-3.el7.x86_64.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-20.10.1-3.el7.x86_64.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-rootless-extras-20.10.1-3.el7.x86_64.rpm
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

从 docker 安装包版本下载对应所有依赖包:

mkdir -p /opt/rpm_cache
yum install --downloadonly --downloaddir=/opt/rpm_cache /opt/docker_rpm/*.rpm
  • 1
  • 2

将依赖包移动到安装包目录下:

cd /opt/rpm_cache
mv * /opt/docker_rpm
cd /opt/docker_rpm
[root@master docker_rpm]# ll
总用量 106232
-rw-r--r--. 1 root root    78256 823 2019 audit-libs-python-2.8.5-4.el7.x86_64.rpm
-rw-r--r--. 1 root root   302068 1112 2018 checkpolicy-2.5-8.el7.x86_64.rpm
-rw-r--r--. 1 root root 34677436 618 09:48 containerd.io-1.4.3-3.1.el7.x86_64.rpm
-rw-r--r--. 1 root root    40816 76 2020 container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm
-rw-r--r--. 1 root root 27890212 618 09:48 docker-ce-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 34723732 618 09:48 docker-ce-cli-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root  9486464 618 09:48 docker-ce-rootless-extras-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root    83764 429 2020 fuse3-libs-3.6.1-4.el7.x86_64.rpm
-rw-r--r--. 1 root root    55796 429 2020 fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
-rw-r--r--. 1 root root    67720 823 2019 libcgroup-0.41-21.el7.x86_64.rpm
-rw-r--r--. 1 root root   115284 1112 2018 libsemanage-python-2.5-14.el7.x86_64.rpm
-rw-r--r--. 1 root root   468316 44 2020 policycoreutils-python-2.5-34.el7.x86_64.rpm
-rw-r--r--. 1 root root    32880 74 2014 python-IPy-0.75-6.el7.noarch.rpm
-rw-r--r--. 1 root root   635184 1112 2018 setools-libs-3.3.8-4.el7.x86_64.rpm
-rw-r--r--. 1 root root    83452 429 2020 slirp4netns-0.4.3-4.el7_8.x86_64.rpm
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

安装:

[root@master docker_rpm]# rpm -ivh *.rpm
警告:containerd.io-1.4.3-3.1.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:libcgroup-0.41-21.el7            ################################# [  7%]
   2:slirp4netns-0.4.3-4.el7_8        ################################# [ 13%]
   3:setools-libs-3.3.8-4.el7         ################################# [ 20%]
   4:python-IPy-0.75-6.el7            ################################# [ 27%]
   5:libsemanage-python-2.5-14.el7    ################################# [ 33%]
   6:fuse3-libs-3.6.1-4.el7           ################################# [ 40%]
   7:fuse-overlayfs-0.7.2-6.el7_8     ################################# [ 47%]
   8:docker-ce-cli-1:20.10.1-3.el7    ################################# [ 53%]
   9:checkpolicy-2.5-8.el7            ################################# [ 60%]
  10:audit-libs-python-2.8.5-4.el7    ################################# [ 67%]
  11:policycoreutils-python-2.5-34.el7################################# [ 73%]
  12:container-selinux-2:2.119.2-1.911################################# [ 80%]
  13:containerd.io-1.4.3-3.1.el7      ################################# [ 87%]
  14:docker-ce-rootless-extras-0:20.10################################# [ 93%]
  15:docker-ce-3:20.10.1-3.el7        ################################# [100%]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

开启docker并将其设置成开机自启动:

[root@master docker_rpm]# systemctl daemon-reload
[root@master docker_rpm]# systemctl start docker
[root@master docker_rpm]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@master docker_rpm]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2023-06-18 09:55:28 CST; 10s ago
     Docs: https://docs.docker.com
 Main PID: 59204 (dockerd)
   CGroup: /system.slice/docker.service
           └─59204 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

618 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.122915885+08:00" level=info msg="ccR...grpc
6月 18 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.122926099+08:00" level=info msg="Cli...grpc
618 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.155614196+08:00" level=info msg="Loa...rt."
618 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.675204341+08:00" level=info msg="Def...ess"
618 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.787624147+08:00" level=info msg="Fir...ing"
618 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.890629800+08:00" level=info msg="Loa...ne."
618 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.975273092+08:00" level=info msg="Doc...10.1
6月 18 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.976202365+08:00" level=info msg="Dae...ion"
6月 18 09:55:28 master systemd[1]: Started Docker Application Container Engine.
6月 18 09:55:28 master dockerd[59204]: time="2023-06-18T09:55:28.010025462+08:00" level=info msg="API...ock"
Hint: Some lines were ellipsized, use -l to show in full.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

配置镜像加速:

[root@master docker_rpm]# mkdir -p /etc/docker
[root@master docker_rpm]# tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
[root@master docker_rpm]# systemctl restart docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

卸载:

[root@slave2 docker_rpm]# rpm -qa | grep docker
docker-ce-cli-20.10.1-3.el7.x86_64
docker-ce-rootless-extras-20.10.1-3.el7.x86_64
docker-ce-20.10.1-3.el7.x86_64
  • 1
  • 2
  • 3
  • 4
yum -y remove docker-ce-cli-20.10.1-3.el7.x86_64
yum -y remove docker-ce-20.10.1-3.el7.x86_64
rm -rf /var/lib/docker
  • 1
  • 2
  • 3

3、yum安装

卸载旧版本:

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

设置镜像仓库:

# 默认是国外的,这里使用阿里云的镜像
yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 1
  • 2
  • 3
  • 4

安装需要的插件:

yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
  • 1
  • 2
  • 3

更新yum软件包索引:

# 更新yum软件包索引
yum makecache fast
  • 1
  • 2

安装docker引擎:

# 安装特定版本 
# 查看有哪些版本
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
yum install docker-ce-20.10.21 docker-ce-cli-20.10.21 containerd.io
# 安装最新版本
yum install docker-ce docker-ce-cli containerd.io
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

启动Docker

systemctl enable docker && systemctl start docker
  • 1

配置Docker镜像加速

vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
# 重启
systemctl restart docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

查看加速是否生效:

docker info
  • 1

验证Docker信息:

docker -v
  • 1

其它Docker命令:

# 停止docker
systemctl stop docker

# 查看docker状态
systemctl status docker
  • 1
  • 2
  • 3
  • 4
  • 5

卸载Docker的命令:

yum remove docker-ce-20.10.21 docker-ce-cli-20.10.21 containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
  • 1
  • 2
  • 3
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号