因为工作需要,我需要离线安装一些东西,比如postgre、redis、nginx等,这些可以通过源码手工编译(在离线情况下可能不太方便)。更方便的是使用docker 镜像。想使用docker镜像的话,首先要安装docker环境,以下是安装docker环境的方法。
因为是离线安装,我带了docker镜像来,不用远程下载镜像,所以第8,9步没有试过,其它的亲测可用,特此记录如下:
-
下载docker
https://download.docker.com/linux/static/stable/x86_64/ -
解压缩
tar xvf docker-24.0.5.tgz.tar
解压后是一些可执行文件 -
将解压的docker拷贝或移动到/usr/bin/目录下
cp docker/* /usr/bin/
/usr/bin下可能有一些可执行文件跟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
-
添加文件可执行权限
chmod +x /etc/systemd/system/docker.service -
配置成功后,重新加载 daemon 服务
systemctl daemon-reload -
解决镜像拉取失败问题
mkdir -p /etc/docker;
vi /etc/docker/daemon.json
文件内容
{
"registry-mirrors":
[
"https://ustc-edu-cn.mirror.aliyuncs.com/",
"https://ccr.ccs.tencentyun.com/",
"https://docker.m.daocloud.io/"
]
}
整体步骤是在csdn的谋篇文章中看到的,但时间太长了,我实在记不起是哪篇文章了,感谢源作者分享,某天源作者看到了给我留言附上源地址,感谢!