# Ubuntu 安装 Docker 容器引擎

**URL:** <https://www.isharkfly.com/t/ubuntu-docker/16721>\
**Category:** DevOps\
**Tags:** docker, ubuntu\
**Created:** [December 7, 2024, 2:37am UTC](https://www.isharkfly.com/t/ubuntu-docker/16721 "2024-12-07T02:37:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hex](https://www.isharkfly.com/user_avatar/www.isharkfly.com/hex/32/21953_2.png) [@hex](https://www.isharkfly.com/u/hex)\
**Post date:** [December 7, 2024, 2:37am UTC](https://www.isharkfly.com/t/ubuntu-docker/16721/1 "2024-12-07T02:37:31Z")

</div>

Ubuntu 安装 Docker 容器的方法非常简单，按照官方的文档拷贝粘贴下就好了。

## 设置仓库

Ubuntu 安装 Docker 之前需要先设置仓库。

拷贝并依次执行下面的代码：

```auto
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

```

## 安装容器引擎

运行下面的命令来运行安装容器引擎。

```auto
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

```

直接在控制台上拷贝运行就行了。

## 校验安装

运行下面的命令来校验 Docker 安装。

如果没有问题，就可以看到 Docker 容器安装成功并能看到输出的 hello-world。

```auto
sudo docker run hello-world

```

 ![2024-12-06_21-36-46](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/3X/c/6/c6ecb35eaeac52d15ce114a30f575630798e985b.jpeg)
