Linux 离线安装docker的过程(一键式安装)
1. docker离线包制作
-
离线包在docker官网下载,不用自己制作,
离线包地址 -
下载需要安装的docker版本,本次需要版本如下
docker-19.03.12.tgz
2. 准备docker.service 系统配置文件
- 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 --containerd=/run/containerd/containerd.sock 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
3. 准备安装脚本和卸载脚本
- 安装脚本 install.sh
#!/usr/bin/env bash echo '解压tar包...' tar -xvf $1 echo '将docker目录移到/usr/bin目录下...' cp docker/* /usr/bin/ echo '将docker.service 移到/etc/systemd/system/ 目录...' cp docker.service /etc/systemd/system/ echo '添加文件权限...' chmod +x /etc/systemd/system/docker.service echo '重新加载配置文件...' systemctl daemon-reload echo '启动docker...' systemctl start docker echo '设置开机自启...' systemctl enable docker.service echo 'docker安装成功...' docker -v
- 卸载脚本 uninstall.sh
#!/usr/bin/env bash echo '删除docker.service...' rm -f /etc/systemd/system/docker.service echo '删除docker文件...' rm -rf /usr/bin/docker* echo '重新加载配置文件' systemctl daemon-reload echo '卸载成功...'
4. 安装
-
4.1 此时目录为:(只需要关注docker-19.03.12.tgz 、docker.service、install.sh、uninstall.sh即可)
-
4.2 执行脚本
chmod +x * bash install.sh docker-19.03.12.tgz 验证安装: docker version Docker version 19.03.12, build 48a66213fe
以上步骤参考地址
5. 普通用户使用docker
- 创建docker组。
sudo groupadd docker
- 将用户添加到该docker组。
sudo usermod ‐aG docker $USER 如果上面一行命令执行不成功,执行下面两句也行 sudo gpasswd -a username docker newgrp docker
- 重新登录(或重启)
6. 远程访问
-
前提-防火墙关闭
systemctl status firewalld sudo systemctl disable firewalld sudo systemctl stop firewalld sudo systemctl status firewalld
-
修改文件 /etc/docker/daemon.json
{ "hosts": ["tcp://<本机IP地址>:2375", "unix:///var/run/docker.sock"], "data-root": "/data/docker", "insecure-registries": ["<仓库的IP地址>:32272"] } sudo systemctl daemon-reload sudo systemctl restart docker 测试是否重启成功 docker ps