云盘链接:
链接:https://pan.baidu.com/s/1aXFf19rl48JmZeHAQmj0Gg
提取码:ai45
云盘文件:
1.原因说明
经常要安装Docker进行测试,安装的过程虽然不复杂,但是会消耗一些时间,故整理了自动化安装脚本,本次安装的文件是docker-20.10.13.tgz
其他版本未测试。
2.脚本内容
脚本文件dockerInstall.sh
内容如下:
#!/bin/bash echo "(1/6): 解压Docker安装文件..." tar -zxvf docker-20.10.13.tgz sleep 5 echo "(1/6): Docker安装文件解压完毕" echo "(2/6): 迁移Docker文件..." mv docker/* /usr/bin/ echo "(2/6): Docker文件迁移完成" echo "(3/6): 将Docker添加到service服务..." cat <<'EOF' > /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 ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always StartLimitBurst=3 StartLimitInterval=60s LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity TasksMax=infinity Delegate=yes KillMode=process [Install] WantedBy=multi-user.target EOF sleep 2 systemctl daemon-reload echo "(3/6): Docker添加到service服务完成" echo "(4/6): 首次启动Docker..." systemctl start docker sleep 2 echo "(4/6): Docker首次启动完毕" echo "(5/6): 查看Docker状态..." systemctl status docker echo "(5/6): Docker状态查看完毕" echo "(6/6): 查询Docker版本..." docker version echo "(6/6): Docker版本查看完毕"
3.脚本执行
首先要赋可执行权限chmod +x dockerInstall.sh
,然后,这里小伙伴要 1注意了、2注意了、3注意了:执行命令的时候要用source dockerInstall.sh
,执行结果如下:
(1/6): 解压Docker安装文件... docker/ docker/dockerd docker/docker docker/containerd-shim docker/docker-init docker/containerd-shim-runc-v2 docker/runc docker/ctr docker/containerd docker/docker-proxy (1/6): Docker安装文件解压完毕 (2/6): 迁移Docker文件... (2/6): Docker文件迁移完成 (3/6): 将Docker添加到service服务... (3/6): Docker添加到service服务完成 (4/6): 首次启动Docker... (4/6): Docker首次启动完毕 (5/6): 查看Docker状态... ● docker.service - Docker Application Container Engine Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2023-03-08 17:22:12 CST; 2s ago Docs: https://docs.docker.com Main PID: 32433 (dockerd) Tasks: 16 Memory: 24.9M CGroup: /system.slice/docker.service ├─32433 /usr/bin/dockerd └─32438 containerd --config /var/run/docker/containerd/containerd.toml --log-level info Mar 08 17:22:11 tcloud dockerd[32433]: time="2023-03-08T17:22:11.946192066+08:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc Mar 08 17:22:11 tcloud dockerd[32433]: time="2023-03-08T17:22:11.946232377+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/contai..." module=grpc Mar 08 17:22:11 tcloud dockerd[32433]: time="2023-03-08T17:22:11.946241152+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc Mar 08 17:22:12 tcloud dockerd[32433]: time="2023-03-08T17:22:12.128125731+08:00" level=info msg="Loading containers: start." Mar 08 17:22:12 tcloud dockerd[32433]: time="2023-03-08T17:22:12.499593583+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.18.0.0/16. Daemon option...d IP address" Mar 08 17:22:12 tcloud dockerd[32433]: time="2023-03-08T17:22:12.592708800+08:00" level=info msg="Loading containers: done." Mar 08 17:22:12 tcloud dockerd[32433]: time="2023-03-08T17:22:12.617247595+08:00" level=info msg="Docker daemon" commit=906f57f graphdriver(s)=overlay2 version=20.10.13 Mar 08 17:22:12 tcloud dockerd[32433]: time="2023-03-08T17:22:12.617359994+08:00" level=info msg="Daemon has completed initialization" Mar 08 17:22:12 tcloud systemd[1]: Started Docker Application Container Engine. Mar 08 17:22:12 tcloud dockerd[32433]: time="2023-03-08T17:22:12.671398366+08:00" level=info msg="API listen on /var/run/docker.sock" Hint: Some lines were ellipsized, use -l to show in full. (5/6): Docker状态查看完毕 (6/6): 查询Docker版本... Client: Version: 20.10.13 API version: 1.41 Go version: go1.16.15 Git commit: a224086 Built: Thu Mar 10 14:01:44 2022 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.13 API version: 1.41 (minimum version 1.12) Go version: go1.16.15 Git commit: 906f57f Built: Thu Mar 10 14:05:58 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.5.10 GitCommit: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc runc: Version: 1.0.3 GitCommit: v1.0.3-0-gf46b6ba2 docker-init: Version: 0.19.0 GitCommit: de40ad0 (6/6): Docker版本查看完毕
4.总结
没有写复杂的可传递参数的脚本,不同版本的Docker安装过程可能有区别。