2024-02-20 17:06:15 +08:00
|
|
|
|
---
|
2024-10-14 16:48:38 +08:00
|
|
|
|
title: 1.3-安装配置
|
2024-02-20 17:06:15 +08:00
|
|
|
|
description: Docker 的安装配置
|
|
|
|
|
keywords:
|
|
|
|
|
- Docker
|
|
|
|
|
- 安装配置
|
|
|
|
|
tags:
|
2024-10-14 16:48:38 +08:00
|
|
|
|
- FormalSciences/ComputerScience
|
|
|
|
|
- OperatingSystem/Docker
|
2024-02-20 17:06:15 +08:00
|
|
|
|
author: 仲平
|
|
|
|
|
date: 2024-02-20
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 官方手册
|
|
|
|
|
|
|
|
|
|
- Get Docker:https://docs.docker.com/get-docker/
|
|
|
|
|
|
|
|
|
|
## 安装脚本
|
|
|
|
|
|
|
|
|
|
### 正式版本
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
|
|
|
|
sh get-docker.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 测试版本
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
curl -fsSL https://test.docker.com -o test-docker.sh
|
|
|
|
|
sh test-docker.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 启动测试
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 默认启动
|
|
|
|
|
sudo systemctl enable docker
|
|
|
|
|
sudo systemctl start docker
|
|
|
|
|
|
|
|
|
|
# 验证是否正确安装
|
|
|
|
|
docker run --rm hello-world
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 镜像加速
|
|
|
|
|
|
|
|
|
|
国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。国内各大云服务商(腾讯云、阿里云、百度云)均提供了 Docker 镜像加速服务,建议根据运行 Docker 的云平台选择对应的镜像加速服务。
|
|
|
|
|
|
|
|
|
|
请首先执行以下命令,查看是否在 `docker.service` 文件中配置过镜像地址。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ systemctl cat docker | grep '\-\-registry\-mirror'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果该命令有输出,那么请执行 `$ systemctl cat docker` 查看 `ExecStart=` 出现的位置,修改对应的文件内容去掉 `--registry-mirror` 参数及其值,并按接下来的步骤进行配置。
|
|
|
|
|
|
|
|
|
|
如果以上命令没有任何输出,那么就可以在 `/etc/docker/daemon.json` 中写入如下内容(如果文件不存在请新建该文件):
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"registry-mirrors": [
|
|
|
|
|
"https://hub-mirror.c.163.com",
|
|
|
|
|
"https://mirror.baidubce.com"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> 注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。
|
|
|
|
|
|
|
|
|
|
最后重新启动服务。
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
|
|
sudo systemctl restart docker
|
|
|
|
|
```
|