1.准备一个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
假定安装包和docker.service文件以及各种镜像包都在/home/carrot/docker中
进入位置
cd /home/carrot/docker
解压
tar -zxvf docker-24.0.7.tgz
复制
- sudo cp docker/* /usr/bin
- sudo cp docker.service /etc/systemd/system/
赋予权限
sudo chmod +x /etc/systemd/system/docker.service
开启docker并并设置开机自启动
- sudo systemctl daemon-reload
- sudo systemctl start docker
- sudo systemctl enable docker.service
将准备好的镜像包导入(以ubuntu镜像包为例)注意xxx.tar 是通过其他服务器执行docker save获取的
sudo docker load -i xxx.tar
使用docker权限不足时
- # 添加docker用户组,一般已存在,不需要执行
-
- sudo groupadd docker
-
- # 将登陆用户加入到docker用户组中
-
- sudo gpasswd -a $USER docker
-
- # 更新用户组
-
- newgrp docker
-
- # 以上操作不行就重启 (慎用)
-
- sudo reboot
镜像导入完成后删除多余文件
- cd ..
- rm -r docker