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/
配置镜像加速:
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
作为服务启动:
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
启动:
systemctl daemon-reload
systemctl start docker
systemctl enable docker
systemctl status docker
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
从 docker 安装包版本下载对应所有依赖包:
mkdir -p /opt/rpm_cache
yum install --downloadonly --downloaddir=/opt/rpm_cache /opt/docker_rpm/*.rpm
将依赖包移动到安装包目录下:
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 8月 23 2019 audit-libs-python-2.8.5-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 302068 11月 12 2018 checkpolicy-2.5-8.el7.x86_64.rpm
-rw-r--r--. 1 root root 34677436 6月 18 09:48 containerd.io-1.4.3-3.1.el7.x86_64.rpm
-rw-r--r--. 1 root root 40816 7月 6 2020 container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm
-rw-r--r--. 1 root root 27890212 6月 18 09:48 docker-ce-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 34723732 6月 18 09:48 docker-ce-cli-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 9486464 6月 18 09:48 docker-ce-rootless-extras-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 83764 4月 29 2020 fuse3-libs-3.6.1-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 55796 4月 29 2020 fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
-rw-r--r--. 1 root root 67720 8月 23 2019 libcgroup-0.41-21.el7.x86_64.rpm
-rw-r--r--. 1 root root 115284 11月 12 2018 libsemanage-python-2.5-14.el7.x86_64.rpm
-rw-r--r--. 1 root root 468316 4月 4 2020 policycoreutils-python-2.5-34.el7.x86_64.rpm
-rw-r--r--. 1 root root 32880 7月 4 2014 python-IPy-0.75-6.el7.noarch.rpm
-rw-r--r--. 1 root root 635184 11月 12 2018 setools-libs-3.3.8-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 83452 4月 29 2020 slirp4netns-0.4.3-4.el7_8.x86_64.rpm
安装:
[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%]
开启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
6月 18 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
6月 18 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.155614196+08:00" level=info msg="Loa...rt."
6月 18 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.675204341+08:00" level=info msg="Def...ess"
6月 18 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.787624147+08:00" level=info msg="Fir...ing"
6月 18 09:55:27 master dockerd[59204]: time="2023-06-18T09:55:27.890629800+08:00" level=info msg="Loa...ne."
6月 18 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.
配置镜像加速:
[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
卸载:
[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
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
3、yum安装
卸载旧版本:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
设置镜像仓库:
# 默认是国外的,这里使用阿里云的镜像
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装需要的插件:
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
更新yum软件包索引:
# 更新yum软件包索引
yum makecache fast
安装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
启动Docker:
systemctl enable docker && systemctl start docker
配置Docker镜像加速:
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
# 重启
systemctl restart docker
查看加速是否生效:
docker info
验证Docker信息:
docker -v
其它Docker命令:文章来源:https://www.toymoban.com/news/detail-512090.html
# 停止docker
systemctl stop docker
# 查看docker状态
systemctl status docker
卸载Docker的命令:文章来源地址https://www.toymoban.com/news/detail-512090.html
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
到了这里,关于Docker安装的三种方式的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!