内网环境下离线安装Docker
内网环境下离线安装Docker
1、系统要求
首先需要确定 CentOS7 的内核版本号,因为 docker 安装要求 Linux 内核版本在 3.10 及以上。查看内核版本号:
uname -r查看系统名称:
cat /etc/redhat-release2、下载Docker
Docker官网:Docker: Accelerated Container Application Development
Docker引擎安装说明:在 CentOS 上安装 Docker 引擎 |Docker 文档
Docker二进制安装说明:从二进制文件安装 Docker 引擎 |Docker 文档
因为这里要使用离线安装Docker,所以为二进制安装。需要下载二进制文件。

选择版本进行下载,下载成功后解压docker包。
tar -zxvf docker-26.1.3.tgz3、安装Docker
将解压出来的docker文件内容拷贝或者移动到 /usr/bin/目录下
cp docker/* /usr/bin/然后就可以使用 docker -v 或者 docker info 命令验证是否可以输出docker信息了。因为没有开启守护进程,docker 其他命令还不能使用。所以需要编写docker.service 文件加入Linux服务当中并开启守护进程。
编辑文件:
vim /etc/systemd/system/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 -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536
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如果需要开启远程服务ExecStart属性修改为以下命令:
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536添加文件可执行权限
chmod +x /etc/systemd/system/docker.service配置成功后,重新加载 daemon 服务
systemctl daemon-reload启动 docker 服务
systemctl start docker4、配置Docker镜像
在目录 etc 下面创建一个 docker 文件夹,进入 docker目录创建 daemon.json 文件
vim daemon.json加入镜像源地址。
{
"registry-mirrors": ["https://docker.m.daocloud.io"],
"log-driver":"json-file",
"log-opts": {"max-size":"1g", "max-file":"3"},
"live-restore": true
}配置成功后,重新启动Docker
5、Docker服务相关命令
重新加载配置文件
systemctl daemon-reload启动 docker 服务
systemctl start docker查看 docker 服务的运行状态
systemctl status docker停止运行
systemctl stop docker重新启动
systemctl restart docker将 docker 服务设置为开机自动启动
systemctl enable docker禁用开机自动启动
systemctl disabled docker查看docker开机自动启动状态 enabled:开启, disabled:关闭
systemctl is-enabled docker.service查看 docker 版本号
docker -v
docker versionDocker启动所有容器
docker start $(docker ps -a -q)6、导出和导入镜像
首先在可以连接网络的服务器上面获取相关软件镜像,然后通过 save 和 load 命令导出和导入镜像。由于导入的镜像没有镜像名称和 tag 版本号,需要使用 docker tag 命令 修改导入的镜像命令。
docker导出镜像:
docker save 99ee9af2b6b1 > redis.tar docker导入镜像:
docker load < redis.tardocker修改镜像标签名称:
docker tag 99ee9af2b6b1 redis:3.2.0