Linux环境离线安装Docker&Docker镜像部署
引子
相信很多同学在项目上线的时候都会遇到没有网络的情况。一般而言,我们都会想到使用Docker 镜像部署,让我们看看搜索引擎给出来Docker的优势吧(如下图)。那么,问题来了,本身部署环境都没有网络,怎么离线安装Docker呢?怎么使用Docker镜像部署项目?OK,让我们开始吧。
一、CenterOS7.0 Docker离线安装
1、下载
(1)Docker安装包
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.8-3.el7.x86_64.rpm
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.2-3.el7.x86_64.rpm
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.8-3.el7.x86_64.rpm
http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-3.el7.noarch.rpm
(2) Docker依赖包
http://mirrors.163.com/centos/7/os/x86_64/Packages/libcgroup-0.41-21.el7.x86_64.rpm libcgroup-devel-0.41-8.el7.x86_64.rpm
http://mirrors.163.com/centos/7/os/x86_64/Packages/libcgroup-devel-0.41-21.el7.x86_64.rpm libcgroup-pam-0.41-8.el7.x86_64.rpm
http://mirrors.163.com/centos/7/os/x86_64/Packages/libcgroup-pam-0.41-21.el7.x86_64.rpm libcgroup-tools-0.41-8.el7.x86_64.rpm
http://mirrors.163.com/centos/7/os/x86_64/Packages/libcgroup-tools-0.41-21.el7.x86_64.rpm
2、安装
rpm -ivh libcgroup-*
rpm -ivh docker-ce-cli-18.09.8-3.el7.x86_64.rpm
rpm -ivh container-selinux-2.107-3.el7.noarch.rpm
rpm -ivh containerd.io-1.2.2-3.el7.x86_64.rpm
rpm -ivh docker-ce-18.09.8-3.el7.x86_64.rpm
3、验证
(1)启动
systemctl start docker
(2)查看状态
systemctl status docker
二、Ubuntu18.04 Docker离线安装
1、下载
https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/
containerd.io_1.4.12-1_amd64.deb
docker-ce-cli_5%3a20.10.12~3-0~ubuntu-bionic_amd64.deb
docker-ce_5%3a20.10.7~3-0~ubuntu-bionic_amd64.deb
https://pkgs.org/
libltdl7_2.4.6-2_amd64.deb
2、安装
sudo dpkg -i libltdl7_2.4.6-2_amd64.deb sudo dpkg -i docker-ce-cli_5%3a20.10.12~3-0~ubuntu-bionic_amd64.deb sudo dpkg -i containerd.io_1.4.12-1_amd64.deb sudo dpkg -i docker-ce_5%3a20.10.7~3-0~ubuntu-bionic_amd64.deb
3、验证
同一中的3
三、Docker镜像部署
1、Docker镜像打包
docker save -o ./test.tar 3808a1012eb9
(注:3808a1012eb9为镜像id)
2、Docker镜像压缩
zip test.zip test.tar
(Tips:文件包会小一半还多)
3、Zip包分包、合包
split -b 3G -d -a 1 attr.zip attr.zip.
cat attr.zip.*>new_attr.zip
4、拷贝到无网服务器
2步骤就会节省大量时间
5、Docker镜像解压
unzip test.zip
6、Docker载入tar包镜像
docker load < test.tar
7、运行部署
docker run --rm xxxxx......