当前位置:   article > 正文

离线部署docker_docker离线部署

docker离线部署

离线部署docker

1、查看操作系统版本
uname -a
  • 1
2、查看操作系统架构
uname -m
  • 1
3、下载docker离线包

下载地址:https://download.docker.com/linux/static/stable/
选择对应的系统架构:

在这里插入图片描述

4、下载docker compose离线包

下载地址:https://github.com/docker/compose/releases
选择对应系统架构的离线安装包:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-R0IdoDyq-1685520495699)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230530154445201.png)]

5、准备 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
  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
6、准备docker的安装脚本文件install.sh
#!/bin/sh
# 
# 说明:离线安装 docker 和 docker-compose 
# 日期:2023-05-30
# 作者:wxs

echo '解压tar包...'
tar -xvf docker-20.10.24.tgz
echo '将docker目录移动/usr/bin目录下...'
cp -p docker/* /usr/bin/
rm -rf docker/
echo '将docker-compose文件复制到/usr/local/bin/目录下,并重命名为docker-compose'
cp docker-compose-darwin-x86_64 /usr/local/bin/docker-compose
echo '添加docker-compose文件权限'
chmod +x /usr/local/bin/docker-compose
echo '将docker.service 移到/etc/systemd/system/ 目录...'
cp docker.service /etc/systemd/system/
echo '添加文件权限...'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件...'
systemctl daemon-reload
echo '启动docker...'
systemctl start docker
echo '设置开机自启...'
systemctl enable docker.service
echo 'docker安装成功...'
docker -v
  • 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
  • 26
  • 27
7、准备docker的卸载脚本文件uninstall.sh
#!/bin/sh
# 
# 说明:卸载离线安装的 docker 和 docker-compose 
# 日期:2023-05-30
# 作者:wxs

echo '删除docker.service...'
rm -f /etc/systemd/system/docker.service
echo '删除docker文件...'
rm -rf /usr/bin/docker*
echo '删除docker-compose文件'
rm -f /usr/local/bin/docker-compose 
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功...'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
8、安装 docker 和 docker compose 离线包

“docker-20.10.24.tgz” (docker压缩包)、“docker-compose-darwin-x86_64” (docker compose文件)、“docker.service” (docker服务文件)、“install.sh” (安装脚本) 、 “uninstall.sh” (卸载脚本)
将这 5 个文件上传到服务器。
因为脚本是在windows系统上面编写的到linux上面执行会有编号问题,所以首先要处理编码问题。
执行处理编码问题的脚本

sed -i 's/\r$//' docker.service
sed -i 's/\r$//' install.sh
sed -i 's/\r$//' uninstall.sh
  • 1
  • 2
  • 3
9、运行 install.sh 文件进行安装
sh install.sh
  • 1

运行 uninstall.sh 文件可以进行卸载

sh uninstall.sh
  • 1
10、验证安装是否成功
docker -v # 验证docker是否安装成功
  • 1
11、设置镜像源
vi /etc/docker/daemon.json

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
  • 1
  • 2
  • 3
  • 4
  • 5
12、刷新配置并重启docker服务
systemctl daemon-reload
systemctl restart docker
  • 1
  • 2
13、查看本地镜像
docker images
  • 1
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号