离线安装
1.下载docker官方离线包
在有外网的环境中先把离线包下载下来
安装包官方地址:https://download.docker.com/linux/static/stable/x86_64/
2.上传离线包到服务器
使用rz命令或ftp工具将下载下来的离线包上传到指定服务器上
3.离线包解压
tar -zxvf docker-20.10.8.tgz
4.复制解压文件到/usr/bin/下
sudo cp docker/* /usr/bin/
5.注册docker为service服务
默认docker的存储路径为/data/docker0
如需修改请修改docker.service
ExecStart=/usr/bin/dockerd --graph=/data/docker0
在/etc/systemd/system/目录下新增docker.service文件
# sudo vi /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
# 如果有搭建私有镜像仓库,--insecure-registry设置为私有镜像仓库地址。
ExecStart=/usr/bin/dockerd --graph /home/docker0
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
6.启动docker服务
赋予docker.service 执行权限
chmod +x /etc/systemd/system/docker.service
重载配置文件以生效
systemctl daemon-reload
启动
sudo systemctl start docker
设置服务开机自启
sudo systemctl enable docker.service
查看服务状态
systemctl status docker
普通用户执行dockers命令
用户组配置文件:/ect/group 即用户组的所有信息都存放在此文件中。
新建用户组 docker,如果用户组已经存在则跳过
sudo groupadd docker
将 appuser用户添加到 docker 组
gpasswd -a appuser docker
更新用户组
newgrp docker
修改docker.sock用户组权限
chown root:docker /var/run/docker.sock
切换普通用户,验证docker命令是否能执行
su - admin
docker version
一键部署
将下载好的包,上传到服务器后,执行命令即可
docker安装包:Docker-install.tar.gz
# tar -zxf Docker-install.tar.gz
# cd Docker-install
# ./install.sh docker-20.10.8.tgz
解压tar包...
docker/
docker/docker-proxy
docker/containerd
docker/dockerd
docker/docker
docker/containerd-shim-runc-v2
docker/ctr
docker/docker-init
docker/runc
docker/containerd-shim
将docker目录移到/usr/bin目录下...
将docker.service 移到/etc/systemd/system/ 目录...
添加文件权限...
重新加载配置文件...
启动docker...
设置开机自启...
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /etc/systemd/system/docker.service.
docker安装成功...
Docker version 20.10.8, build 3967b7d
Docker Compose version v2.11.0
评论区