ubuntu-install-docker.sh
· 688 B · Bash
Raw
#!/bin/bash
# 更新现有的包列表
sudo apt update
# 安装依赖包
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
# 添加 Docker 的官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 设置 Docker 仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 更新包列表
sudo apt update
# 安装 Docker
sudo apt install -y docker-ce
# 启动 Docker 并设置为开机自启
sudo systemctl start docker
sudo systemctl enable docker
# 验证 Docker 安装
sudo docker run hello-world
echo "Docker 已成功安装并运行!"
| 1 | #!/bin/bash |
| 2 | |
| 3 | # 更新现有的包列表 |
| 4 | sudo apt update |
| 5 | |
| 6 | # 安装依赖包 |
| 7 | sudo apt install -y apt-transport-https ca-certificates curl software-properties-common |
| 8 | |
| 9 | # 添加 Docker 的官方 GPG 密钥 |
| 10 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - |
| 11 | |
| 12 | # 设置 Docker 仓库 |
| 13 | sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |
| 14 | |
| 15 | # 更新包列表 |
| 16 | sudo apt update |
| 17 | |
| 18 | # 安装 Docker |
| 19 | sudo apt install -y docker-ce |
| 20 | |
| 21 | # 启动 Docker 并设置为开机自启 |
| 22 | sudo systemctl start docker |
| 23 | sudo systemctl enable docker |
| 24 | |
| 25 | # 验证 Docker 安装 |
| 26 | sudo docker run hello-world |
| 27 | |
| 28 | echo "Docker 已成功安装并运行!" |
| 29 |