docker 离线镜像下载网址: https://docs.docker.com/engine/install/centos/
docker官网:centos 安装:https://docs.docker.com/engine/install/centos/
[root@vcontroller docker_rpm]# ll
total 104288
-rw-r--r--. 1 root root 34677436 Dec 21 20:23 containerd.io-1.4.3-3.1.el7.x86_64.rpm
-rw-r--r--. 1 root root 27890212 Dec 21 20:15 docker-ce-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 34723732 Dec 21 20:15 docker-ce-cli-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 9486464 Dec 21 20:23
docker-ce-rootless-extras-20.10.1-3.el7.x86_64.rpm
从docker 安装包版本下载对应所有依赖包
yum install --downloadonly --downloaddir=/opt/rpm_cache /root/docker_rpm/*.rpm
将所有依赖包和docker 安装包版本放在一起
以下就可以离线安装了
安装docker 20-*
[root@vcontroller ~]# cd docker_rpm_next
[root@vcontroller docker_rpm_next]# ll
total 106292
-rw-r--r--. 1 root root 78256 Dec 21 20:30 audit-libs-python-2.8.5-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 302068 Dec 21 20:30 checkpolicy-2.5-8.el7.x86_64.rpm
-rw-r--r--. 1 root root 34677436 Dec 21 20:53 containerd.io-1.4.3-3.1.el7.x86_64.rpm
-rw-r--r--. 1 root root 40816 Dec 21 20:30 container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm
-rw-r--r--. 1 root root 27890212 Dec 21 20:53 docker-ce-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 34723732 Dec 21 20:53 docker-ce-cli-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 9486464 Dec 21 20:53 docker-ce-rootless-extras-20.10.1-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 83764 Dec 21 20:30 fuse3-libs-3.6.1-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 55796 Dec 21 20:30 fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
-rw-r--r--. 1 root root 67720 Dec 21 20:30 libcgroup-0.41-21.el7.x86_64.rpm
-rw-r--r--. 1 root root 57460 Dec 21 20:30 libseccomp-2.3.1-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 115284 Dec 21 20:30 libsemanage-python-2.5-14.el7.x86_64.rpm
-rw-r--r--. 1 root root 468316 Dec 21 20:30 policycoreutils-python-2.5-34.el7.x86_64.rpm
-rw-r--r--. 1 root root 32880 Dec 21 20:30 python-IPy-0.75-6.el7.noarch.rpm
-rw-r--r--. 1 root root 635184 Dec 21 20:30 setools-libs-3.3.8-4.el7.x86_64.rpm
-rw-r--r--. 1 root root 83452 Dec 21 20:30 slirp4netns-0.4.3-4.el7_8.x86_64.rpm
[root@vcontroller docker_rpm_next]# rpm -ivh *.rpm
warning: containerd.io-1.4.3-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:libseccomp-2.3.1-4.el7 ################################# [ 6%]
2:libcgroup-0.41-21.el7 ################################# [ 13%]
3:slirp4netns-0.4.3-4.el7_8 ################################# [ 19%]
4:setools-libs-3.3.8-4.el7 ################################# [ 25%]
5:python-IPy-0.75-6.el7 ################################# [ 31%]
6:libsemanage-python-2.5-14.el7 ################################# [ 38%]
7:fuse3-libs-3.6.1-4.el7 ################################# [ 44%]
8:fuse-overlayfs-0.7.2-6.el7_8 ################################# [ 50%]
9:docker-ce-cli-1:20.10.1-3.el7 ################################# [ 56%]
10:checkpolicy-2.5-8.el7 ################################# [ 63%]
11:audit-libs-python-2.8.5-4.el7 ################################# [ 69%]
12:policycoreutils-python-2.5-34.el7################################# [ 75%]
13:container-selinux-2:2.119.2-1.911################################# [ 81%]
14:containerd.io-1.4.3-3.1.el7 ################################# [ 88%]
15:docker-ce-rootless-extras-0:20.10################################# [ 94%]
16:docker-ce-3:20.10.1-3.el7 ################################# [100%]
[root@vcontroller docker_rpm_next]# docker -v
Docker version 20.10.1, build 831ebea
导入镜像:
1、测试docker 运行状态
[root@vcontroller ~]# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
2、开启docker并将其设置成开机自启动
[root@vcontroller ~]# systemctl start docker
[root@vcontroller ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@vcontroller ~]# docker -v
Docker version 20.10.1, build 831ebea
[root@vcontroller ~]# cd docker_offline_images/
[root@vcontroller docker_offline_images]# ll
total 2308780
-rw-r--r--. 1 root root 1063202816 Dec 21 21:23 xxxxxxx.tar
-rw-r--r--. 1 root root 1300985344 Dec 21 21:25 yyyyyyyy.tar
[root@vcontroller docker_offline_images]# docker load -i *.tar
"docker load" accepts no arguments.
See 'docker load --help'.
Usage: docker load [OPTIONS]
Load an image from a tar archive or STDIN
[root@vcontroller docker_offline_images]# docker load -i *.tar
一个一个的加载离线镜像
[root@vcontroller docker_offline_images]# docker load -i xxxxxx.tar
2653d992f4ef: Loading layer [==================================================>] 216.5MB/216.5MB
efec8e2952f2: Loading layer [==================================================>] 1.084GB/1.084GB
a1efef88078d: Loading layer [==================================================>] 23.55kB/23.55kB
Loaded image ID: sha256:0f92b564353c7e8b928bf1fd9711d81061f652356c99e26b370fb8c9bbe9f557
[root@vcontroller docker_offline_images]# docker load -i yyyyyyy.tar
b6ca02dfe5e6: Loading layer [==================================================>] 128.9MB/128.9MB
60a0858edcd5: Loading layer [==================================================>] 45.19MB/45.19MB
9e9ecb074181: Loading layer [==================================================>] 1.295MB/1.295MB
8a8d2d3a56ef: Loading layer [==================================================>] 3.584kB/3.584kB
c01141679a41: Loading layer [==================================================>] 3.584kB/3.584kB
fbfa3c9a96db: Loading layer [==================================================>] 143.2MB/143.2MB
ef5e2850ccfe: Loading layer [==================================================>] 426kB/426kB
e947aa7de530: Loading layer [==================================================>] 942.6kB/942.6kB
ff3623a2056c: Loading layer [==================================================>] 2.561MB/2.561MB
4134cbaa0b40: Loading layer [==================================================>] 1.536kB/1.536kB
cc666f6e8c4c: Loading layer [==================================================>] 740.3MB/740.3MB
c810edc49a3e: Loading layer [==================================================>] 3.072kB/3.072kB
44beb7e7df1d: Loading layer [==================================================>] 2.048kB/2.048kB
d036079f0639: Loading layer [==================================================>] 3.584kB/3.584kB
41cbab2ea00d: Loading layer [==================================================>] 9.216kB/9.216kB
09bf50b3392a: Loading layer [==================================================>] 18.43kB/18.43kB
3563bfcefc39: Loading layer [==================================================>] 25.6kB/25.6kB
fd0276a63f12: Loading layer [==================================================>] 11.78kB/11.78kB
45f016ad819f: Loading layer [==================================================>] 6.144kB/6.144kB
488c99b975f1: Loading layer [==================================================>] 28.67kB/28.67kB
d5bbabcf215c: Loading layer [==================================================>] 9.216kB/9.216kB
8d1113e446d4: Loading layer [==================================================>] 4.608kB/4.608kB
a67afe984d0a: Loading layer [==================================================>] 3.072kB/3.072kB
2602b2e531a4: Loading layer [==================================================>] 60.42kB/60.42kB
19cc615c6379: Loading layer [==================================================>] 4.608kB/4.608kB
89ea39d7439e: Loading layer [==================================================>] 3.584kB/3.584kB
347b33688333: Loading layer [==================================================>] 12.8kB/12.8kB
Loaded image: sunyasec.com/csos/analyzer:v2.0
[root@vcontroller docker_offline_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@vcontroller docker_offline_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@vcontroller docker_offline_images]# docker run -itd -net host -name analyzer_v1
unknown shorthand flag: 'n' in -net
See 'docker run --help'.
[root@vcontroller docker_offline_images]#
[root@vcontroller docker_offline_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
0f92b564353c 5 days ago 1.29GB
sunyasec.com/csos/analyzer v2.0 f22f710c888f 18 months ago 1.01GB
[root@vcontroller docker_offline_images]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
0f92b564353c 5 days ago 1.29GB
sunyasec.com/csos/analyzer v2.0 f22f710c888f 18 months ago 1.01GB
根据镜像id载入容器:
[root@vcontroller docker_offline_images]# docker run -itd --net host --name xxxxx 0f92b564353c
7f6bfee89146f3188cd7167debebc50b9acf9e5b5fab8a8ed12ead41cbb2d67a
[root@vcontroller docker_offline_images]# docker run -itd --net host --name yyyyyyy f22f710c888f
f3c46682cac09e7f3e5e526a3f61d601db91491b9501afc5021f92a32e94f02b
[root@vcontroller docker_offline_images]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3c46682cac0 f22f710c888f "/etc/init.d/xxxx.?? 13 seconds ago Up 12 seconds xxxxx
7f6bfee89146 0f92b564353c "/etc/init.d/yyyyyy.sh" 2 minutes ago Up 2 minutes yyyyyy
容器已经启动,进入容器里面进行查看,并能退出容器,设置docker 容器开机自启动
[root@vcontroller docker_offline_images]# docker exec -it f3c46682cac0 /bin/bash
root@vcontroller:/sunya/init.d# exit
[root@vcontroller docker_offline_images]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3c46682cac0 f22f710c888f "/etc/init.d/xxx.?? 8 minutes ago Up 8 minutes xxxxxxx
7f6bfee89146 0f92b564353c "/etc/init.d/yyyy.sh" 10 minutes ago Up 10 minutes yyyyyyy
[root@vcontroller docker_offline_images]# docker update --restart=always f3c46682cac0
f3c46682cac0
[root@vcontroller docker_offline_images]# docker update --restart=always 7f6bfee89146
7f6bfee89146
离线容器压缩包可以自行找一个,关于docker安装包和依赖包,我已经上传到我的资料中
https://download.csdn.net/download/shunzi2016/13750054
一 自动化操作
获取image id 自动删除
docker images | grep -E "xxxxx" | awk '{print $3}' | uniq | xargs -I {} docker rmi --force {}
镜像模糊匹配删除
docker images | grep -E "xxxxx" | awk '{print $3}' | uniq | xargs -I {} docker rmi --force {}
镜像模糊匹配批量创建容器 xxxxx 为模糊条件,不写为全部
docker images | grep -E "xxxxx" | awk '{print $1}' | uniq | xargs -I {} docker run -itd --net host --name {}_elk {}
docker images | awk '{print $3}' | uniq | xargs -I {} docker run -itd --net host --name {}_elk {}
docker ps
自动批量部署开机自启动容器,
docker ps| grep -E "xxxxx" | awk '{print $3}' | uniq | xargs -I {} update --restart=always {}
docker ps| awk '{print $3}' | uniq | xargs -I {} update --restart=always {}