2026-04-02 23:12:36 +08:00

60 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: ubuntu安装docker engine
createTime: 2023/06/27 09:54:12
tags:
- docker
- Ubuntu
categories:
- 随记
---
对于无图形界面的 Ubuntu Server直接安装[Dokcer Engine](https://docs.docker.com/engine/install/ubuntu/)就可以。
1. 安装依赖
```bash
sudo apt update
sudo apt install ca-certificates curl gnupg
```
2. 配置 docker 的 GPG 密钥
```bash
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
```
3. 添加 Docker 的 apt 仓库
```bash
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
4. 安装 Docker Engine
```bash
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# 验证
docker version
docker compose version
# Hello World
sudo docker run hello-world
```
5. 配置国内镜像
```bash
vi /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}
sudo service docker restart
```