项目背景:由于项目需要保密,不能联网,因此需要离线安装docker容器并导入镜像。
一、下载二进制安装包
先在下面网址中下载docker容器的二进制安装包,Ubuntu系统选择最后一个x86_64
https://download.docker.com/linux/static/stable/
二、解压下载的docker容器的二进制安装包
ljjx@ljjx-virtual-machine:~/test$ sudo tar -xvf docker-24.0.5.tgz
三、将可执行文件复制到系统运行命令下
将二进制文件移动到可执行文件路径上的目录,一般是 /usr/bin/
ljjx@ljjx-virtual-machine:~/test$ sudo cp docker/* /usr/bin/
此处需要注意:不要直接在 /usr/bin/目录下解压第一步下载的二进制的压缩包,否则在打开docker容器时会报如下错误:
ljjx@ljjx-virtual-machine:/usr/bin$ sudo systemctl start docker && systemctl enable docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.
四、docker容器项目配置
在/etc/systemd/system目录下创建docker.service文件,并将相关参数写入该文件中,并配置如下内容保存。
创建文件并打开采用下面的命令:
ljjx@ljjx-virtual-machine:~/test$ sudo vim /usr/lib/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
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
五、docker容器的启动
启动命令:
ljjx@ljjx-virtual-machine:~/test$ sudo systemctl start docker
查看docker运行状态:
ljjx@ljjx-virtual-machine:~/test$ sudo systemctl status docker
结果如下图所示: