内网服务器安装docker

本文详细介绍了在内网服务器上安装Docker的步骤,包括下载安装文件、上传到服务器、解压并移动到指定目录、配置systemd服务、修改工作目录、设置开机自启以及验证Docker服务是否启动成功。此外,还提供了配置文件docker.service的内容和修改docker工作目录的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、下载docker的安装文件

下载地址: https://download.docker.com/linux/static/stable/x86_64/
选择合适的版本,本文下载 20.10.14
在这里插入图片描述

2、将下载的压缩包上传到服务器,在服务器解压并移动到/usr/bin目录下

# 提示:上传压缩包到服务器是使用xftp或者其它方式,本文使用的是xftp先上传到有外网的服务器,然后再在有外网的服务器使用scp命令上传到内网服务器
# 进入到压缩包所在的目录,解压(tar命令)并且移动(mv命令)可执行文件到 /usr/bin 目录下
tar zxf docker-20.10.14.tgz && mv docker/* /usr/bin/

3、使用systemctl管理docker服务

# 进入 /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 tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP
# 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

4、给 docker.service 文件添加执行权限

chmod a+x /etc/systemd/system/docker.service

5、重新加载配置文件(每次有修改docker.service文件时都要重新加载下)

systemctl daemon-reload # 重载 systemd 下 xxx.service 文件
systemctl start docker # 启动 docker
systemctl enable docker # 设置开机自启
systemctl is-enabled docker # 查看是否设置开机启动

6、修改 docker 工作目录(可选:不修改时默认路径是/var/lib/docker/)

vim /etc/docker/daemon.json
# 内容如下
{
    "data-root": "/data/docker"
}

7、重启 docker 服务

systemctl restart docker

8、验证 docker 是否启动成功

systemctl status docker # 查看docker运行状态
docker version # 查看docker版本
docker info # 查看docker相关信息

参考地址:
http://www.360doc.com/content/22/0305/19/39194723_1020231096.shtml
https://blog.youkuaiyun.com/houmenghu/article/details/123690559

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值