linux 怎么安装docker
时间: 2024-07-24 08:01:37 浏览: 146
Linux安装docker
在Linux上安装Docker通常有几种常见的方法,取决于你的操作系统版本和具体的发行版。以下是基于Ubuntu的步骤,其他发行版(如Debian、CentOS等)也大体相似:
1. **更新系统**:
```sh
sudo apt-get update
```
2. **安装依赖**:
```sh
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
```
3. **添加Docker GPG key**:
```sh
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```
4. **添加Docker仓库**:
```sh
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
5. **更新apt缓存并安装Docker CE(Community Edition)**:
```sh
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
```
6. **启动和启用Docker服务**:
```sh
sudo systemctl start docker
sudo systemctl enable docker
```
7. **验证安装**:
```sh
sudo docker run hello-world
```
完成以上步骤后,你应该可以正常地使用Docker了。
阅读全文