1.下载docker官方离线包
在有外网的环境中先把离线包下载下来
安装包官方地址:https://download.docker.com/linux/static/stable/x86_64/
2.上传离线包到服务器
使用scp命令或ftp工具将下载下来的离线包上传到指定服务器上
3.离线包解压
tar -zxvf docker-20.10.8.tgz
4.复制解压文件到/usr/bin/下
sudo cp docker/* /usr/bin/
5.注册docker为service服务
在/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 --selinux-enabled=false --insecure-registry=127.0.0.1
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
方法一:
用户组配置文件:/ect/group 即用户组的所有信息都存放在此文件中。
新建用户组 docker,如果用户组已经存在则跳过
sudo groupadd docker
将 appuser用户添加到 docker 组
gpasswd -a appuser docker
刷新 docker 组
newgrp docker
方法二:
解决办法就是修改 /var/run/docker.sock 文件的权限,让普通用户也可以访问。
修改文件权限
sudo chmod 666 /var/run/docker.sock
镜像打包
docker save 镜像名称:镜像版本 >打包后的文件名字.tar
将镜像加载到docker系统中
docker load -i 打包后的文件名字.tar