ubuntu18.04服务器安装docker教程
时间: 2024-12-18 16:26:05 浏览: 6
在Ubuntu 18.04服务器上安装Docker,你需要先更新系统包并添加Docker的官方apt源。以下是详细的步骤:
1. **更新系统**:
```bash
sudo apt update
```
2. **添加Docker GPG密钥**:
```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```
3. **修改apt源**:
将以下行添加到 `/etc/apt/sources.list.d/docker.list` 文件(如果不存在就创建它),替换 `<version>` 为 Docker 的最新稳定版本(如 `20.04` 或 `latest`):
```
deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu <version> stable
```
4. **更新apt索引**:
```bash
sudo apt-get update
```
5. **安装Docker**:
```bash
sudo apt install docker-ce docker-ce-cli containerd.io
```
6. **启动和启用Docker服务**:
```bash
sudo systemctl start docker
sudo systemctl enable docker
```
7. **验证Docker是否安装成功**:
```bash
docker run hello-world
```
阅读全文