mirror of
https://github.com/yeasy/docker_practice.git
synced 2025-06-08 09:52:11 +08:00
Compare commits
57 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3a9d4bff61 | ||
![]() |
4bc29c0300 | ||
![]() |
65bc905920 | ||
![]() |
1b7d941fcd | ||
![]() |
e0ff3d315a | ||
![]() |
09de77b543 | ||
![]() |
344fc8bd3c | ||
![]() |
7ec5772432 | ||
![]() |
355dd3b051 | ||
![]() |
ca011164c2 | ||
![]() |
0f2956a646 | ||
![]() |
da7991660e | ||
![]() |
391c6364a0 | ||
![]() |
99433b2e45 | ||
![]() |
32c6a91aa9 | ||
![]() |
bea7b8d3f4 | ||
![]() |
1be1db5a43 | ||
![]() |
7052cea8a3 | ||
![]() |
584087ad46 | ||
![]() |
dd6b022429 | ||
![]() |
46020ff786 | ||
![]() |
3ccba8afb4 | ||
![]() |
f5e6a67664 | ||
![]() |
439264a87f | ||
![]() |
41558e73b4 | ||
![]() |
f34a985a78 | ||
![]() |
bd8387083a | ||
![]() |
8d129d0ead | ||
![]() |
85c5a280a4 | ||
![]() |
98044d04b2 | ||
![]() |
57873b1143 | ||
![]() |
6acf209b9a | ||
![]() |
ed4b3efd3b | ||
![]() |
eb327bf908 | ||
![]() |
cc683fdb56 | ||
![]() |
13b8e12f44 | ||
![]() |
ce4428adfb | ||
![]() |
6443ddc07c | ||
![]() |
ce5ae6a360 | ||
![]() |
35b264694b | ||
![]() |
e76b0b66a0 | ||
![]() |
d80f3430b2 | ||
![]() |
d9c5d2fb43 | ||
![]() |
fe7530c3f6 | ||
![]() |
30f00323e0 | ||
![]() |
93ea51ff07 | ||
![]() |
85be3008fa | ||
![]() |
88f9183fd5 | ||
![]() |
1c4a43e34e | ||
![]() |
7014e4d87c | ||
![]() |
18028b8eaa | ||
![]() |
7c78d1c256 | ||
![]() |
d4c6e590c6 | ||
![]() |
1e415ac76c | ||
![]() |
664ac88c85 | ||
![]() |
734079661d | ||
![]() |
1ed8c2c81f |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: yeasy
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
6
.github/workflows/check-link.yml
vendored
6
.github/workflows/check-link.yml
vendored
@ -1,8 +1,6 @@
|
||||
name: Check link
|
||||
|
||||
on:
|
||||
# push:
|
||||
# pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@ -10,9 +8,7 @@ jobs:
|
||||
name: check-link
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- uses: actions/checkout@v4.1.1
|
||||
# search Issues :-(
|
||||
- run: |
|
||||
docker run -i --rm \
|
||||
|
11
.github/workflows/ci.yaml
vendored
11
.github/workflows/ci.yaml
vendored
@ -1,10 +1,10 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
name: CI
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash --noprofile --norc -exo pipefail {0}
|
||||
@ -14,9 +14,7 @@ jobs:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 2
|
||||
- uses: actions/checkout@v4.1.1
|
||||
- name: Build Gitbook
|
||||
uses: docker://yeasy/docker_practice
|
||||
with:
|
||||
@ -68,8 +66,8 @@ jobs:
|
||||
PCIT_USERNAME: khs1994
|
||||
- name: vuepress
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
sudo rm -rf _book
|
||||
# npm i vuepress --save-dev
|
||||
npm i
|
||||
|
||||
git clone https://github.com/docker-practice/.vuepress .vuepress2
|
||||
@ -80,7 +78,6 @@ jobs:
|
||||
npx vuepress --version
|
||||
|
||||
npm run vuepress:build
|
||||
# echo "vuepress.docker-practice.com" > .vuepress/dist/CNAME
|
||||
echo "vuepress.mirror.docker-practice.com" > .vuepress/dist/CNAME
|
||||
|
||||
cp -r _images .vuepress/dist
|
||||
|
@ -75,6 +75,7 @@
|
||||
* [自定义网桥](advanced_network/bridge.md)
|
||||
* [工具和示例](advanced_network/example.md)
|
||||
* [编辑网络配置文件](advanced_network/config_file.md)
|
||||
* [配置 HTTP/HTTPS 网络代理](advanced_network/http_https_proxy.md)
|
||||
* [实例:创建一个点到点连接](advanced_network/ptp.md)
|
||||
* [Docker Buildx](buildx/README.md)
|
||||
* [BuildKit](buildx/buildkit.md)
|
||||
|
74
advanced_network/http_https_proxy.md
Normal file
74
advanced_network/http_https_proxy.md
Normal file
@ -0,0 +1,74 @@
|
||||
# 配置 HTTP/HTTPS 网络代理
|
||||
|
||||
使用Docker的过程中,因为网络原因,通常需要使用 HTTP/HTTPS 代理来加速镜像拉取、构建和使用。下面是常见的三种场景。
|
||||
|
||||
## 为 dockerd 设置网络代理
|
||||
|
||||
"docker pull" 命令是由 dockerd 守护进程执行。而 dockerd 守护进程是由 systemd 管理。因此,如果需要在执行 "docker pull" 命令时使用 HTTP/HTTPS 代理,需要通过 systemd 配置。
|
||||
|
||||
- 为 dockerd 创建配置文件夹。
|
||||
```
|
||||
sudo mkdir -p /etc/systemd/system/docker.service.d
|
||||
```
|
||||
|
||||
- 为 dockerd 创建 HTTP/HTTPS 网络代理的配置文件,文件路径是 /etc/systemd/system/docker.service.d/http-proxy.conf 。并在该文件中添加相关环境变量。
|
||||
```
|
||||
[Service]
|
||||
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
|
||||
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
|
||||
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
|
||||
```
|
||||
|
||||
- 刷新配置并重启 docker 服务。
|
||||
```
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart docker
|
||||
```
|
||||
|
||||
## 为 docker 容器设置网络代理
|
||||
|
||||
在容器运行阶段,如果需要使用 HTTP/HTTPS 代理,可以通过更改 docker 客户端配置,或者指定环境变量的方式。
|
||||
|
||||
- 更改 docker 客户端配置:创建或更改 ~/.docker/config.json,并在该文件中添加相关配置。
|
||||
```
|
||||
{
|
||||
"proxies":
|
||||
{
|
||||
"default":
|
||||
{
|
||||
"httpProxy": "http://proxy.example.com:8080/",
|
||||
"httpsProxy": "http://proxy.example.com:8080/",
|
||||
"noProxy": "localhost,127.0.0.1,.example.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- 指定环境变量:运行 "docker run" 命令时,指定相关环境变量。
|
||||
|
||||
| 环境变量 | docker run 示例 |
|
||||
| -------- | ---------------- |
|
||||
| HTTP_PROXY | --env HTTP_PROXY="http://proxy.example.com:8080/" |
|
||||
| HTTPS_PROXY | --env HTTPS_PROXY="http://proxy.example.com:8080/" |
|
||||
| NO_PROXY | --env NO_PROXY="localhost,127.0.0.1,.example.com" |
|
||||
|
||||
## 为 docker build 过程设置网络代理
|
||||
|
||||
在容器构建阶段,如果需要使用 HTTP/HTTPS 代理,可以通过指定 "docker build" 的环境变量,或者在 Dockerfile 中指定环境变量的方式。
|
||||
|
||||
- 使用 "--build-arg" 指定 "docker build" 的相关环境变量
|
||||
```
|
||||
docker build \
|
||||
--build-arg "HTTP_PROXY=http://proxy.example.com:8080/" \
|
||||
--build-arg "HTTPS_PROXY=http://proxy.example.com:8080/" \
|
||||
--build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" .
|
||||
```
|
||||
|
||||
- 在 Dockerfile 中指定相关环境变量
|
||||
|
||||
| 环境变量 | Dockerfile 示例 |
|
||||
| -------- | ---------------- |
|
||||
| HTTP_PROXY | ENV HTTP_PROXY="http://proxy.example.com:8080/" |
|
||||
| HTTPS_PROXY | ENV HTTPS_PROXY="http://proxy.example.com:8080/" |
|
||||
| NO_PROXY | ENV NO_PROXY="localhost,127.0.0.1,.example.com" |
|
||||
|
@ -167,9 +167,9 @@ RUN apt-get update && apt-get install -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
```
|
||||
|
||||
其中 `s3cmd` 指令指定了一个版本号 `1.1.*`。如果之前的镜像使用的是更旧的版本,指定新的版本会导致 `apt-get udpate` 缓存失效并确保安装的是新版本。
|
||||
其中 `s3cmd` 指令指定了一个版本号 `1.1.*`。如果之前的镜像使用的是更旧的版本,指定新的版本会导致 `apt-get update` 缓存失效并确保安装的是新版本。
|
||||
|
||||
另外,清理掉 apt 缓存 `var/lib/apt/lists` 可以减小镜像大小。因为 `RUN` 指令的开头为 `apt-get udpate`,包缓存总是会在 `apt-get install` 之前刷新。
|
||||
另外,清理掉 apt 缓存 `var/lib/apt/lists` 可以减小镜像大小。因为 `RUN` 指令的开头为 `apt-get update`,包缓存总是会在 `apt-get install` 之前刷新。
|
||||
|
||||
> 注意:官方的 Debian 和 Ubuntu 镜像会自动运行 apt-get clean,所以不需要显式的调用 apt-get clean。
|
||||
|
||||
@ -329,7 +329,7 @@ $ docker run --rm -it postgres bash
|
||||
|
||||
如果某个服务不需要特权执行,建议使用 `USER` 指令切换到非 root 用户。先在 `Dockerfile` 中使用类似 `RUN groupadd -r postgres && useradd -r -g postgres postgres` 的指令创建用户和用户组。
|
||||
|
||||
>注意:在镜像中,用户和用户组每次被分配的 UID/GID 都是不确定的,下次重新构建镜像时被分配到的 UID/GID 可能会不一样。如果要依赖确定的 UID/GID,你应该显示的指定一个 UID/GID。
|
||||
>注意:在镜像中,用户和用户组每次被分配的 UID/GID 都是不确定的,下次重新构建镜像时被分配到的 UID/GID 可能会不一样。如果要依赖确定的 UID/GID,你应该显式的指定一个 UID/GID。
|
||||
|
||||
你应该避免使用 `sudo`,因为它不可预期的 TTY 和信号转发行为可能造成的问题比它能解决的问题还多。如果你真的需要和 `sudo` 类似的功能(例如,以 root 权限初始化某个守护进程,以非 root 权限执行它),你可以使用 [gosu](https://github.com/tianon/gosu)。
|
||||
|
||||
|
@ -10,17 +10,17 @@ CentOS(Community Enterprise Operating System,中文意思是:社区企业
|
||||
|
||||
### 使用 CentOS 官方镜像
|
||||
|
||||
使用 `docker run` 直接运行最新的 `CentOS` 镜像,并登录 `bash`。
|
||||
使用 `docker run` 直接运行 `CentOS 7` 镜像,并登录 `bash`。
|
||||
|
||||
```bash
|
||||
$ docker run -it centos bash
|
||||
$ docker run -it centos:7 bash
|
||||
Unable to find image 'centos:latest' locally
|
||||
latest: Pulling from library/centos
|
||||
3d8673bd162a: Pull complete
|
||||
Digest: sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4
|
||||
Status: Downloaded newer image for centos:latest
|
||||
[root@43eb3b194d48 /]# cat /etc/redhat-release
|
||||
CentOS Linux release 7.2.1511 (Core)
|
||||
CentOS Linux release 7.9.2009 (Core)
|
||||
```
|
||||
|
||||
## Fedora 系统简介
|
||||
|
@ -1,2 +1,2 @@
|
||||
Django>=2.0,<3.0
|
||||
Django>=5.0.6,<6.0
|
||||
psycopg2>=2.7,<3.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
# 数据卷
|
||||
|
||||
`数据卷` 是一个可供一个或多个容器使用的特殊目录,它绕过 UFS,可以提供很多有用的特性:
|
||||
`数据卷` 是一个可供一个或多个容器使用的特殊目录,它绕过 UnionFS,可以提供很多有用的特性:
|
||||
|
||||
* `数据卷` 可以在容器之间共享和重用
|
||||
|
||||
|
@ -40,7 +40,7 @@ FROM scratch
|
||||
|
||||
如果你以 `scratch` 为基础镜像的话,意味着你不以任何镜像为基础,接下来所写的指令将作为镜像第一层开始存在。
|
||||
|
||||
不以任何系统为基础,直接将可执行文件复制进镜像的做法并不罕见,对于 Linux 下静态编译的程序来说,并不需要有操作系统提供运行时支持,所需的一切库都已经在可执行文件里了,因此直接 `FROM scratch` 会让镜像体积更加小巧。使用 [Go 语言](https://golang.google.cn/) 开发的应用很多会使用这种方式来制作镜像,这也是为什么有人认为 Go 是特别适合容器微服务架构的语言的原因之一。
|
||||
不以任何系统为基础,直接将可执行文件复制进镜像的做法并不罕见,对于 Linux 下静态编译的程序来说,并不需要有操作系统提供运行时支持,所需的一切库都已经在可执行文件里了,因此直接 `FROM scratch` 会让镜像体积更加小巧。使用 [Go 语言](https://golang.google.cn/) 开发的应用很多会使用这种方式来制作镜像,这也是有人认为 Go 是特别适合容器微服务架构的语言的原因之一。
|
||||
|
||||
## RUN 执行命令
|
||||
|
||||
|
@ -4,7 +4,7 @@ WORKDIR /app
|
||||
|
||||
COPY package.json /app/
|
||||
|
||||
RUN npm i --registry=https://registry.npm.taobao.org \
|
||||
RUN npm i --registry=https://registry.npmmirror.com \
|
||||
&& rm -rf ~/.npm
|
||||
|
||||
COPY src /app/src
|
||||
|
@ -8,7 +8,7 @@ COPY package.json /app/
|
||||
|
||||
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
|
||||
--mount=type=cache,target=/root/.npm,id=npm_cache \
|
||||
npm i --registry=https://registry.npm.taobao.org
|
||||
npm i --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY src /app/src
|
||||
|
||||
|
@ -40,7 +40,7 @@ CMD service nginx start
|
||||
|
||||
对于容器而言,其启动程序就是容器应用进程,容器就是为了主进程而存在的,主进程退出,容器就失去了存在的意义,从而退出,其它辅助进程不是它需要关心的东西。
|
||||
|
||||
而使用 `service nginx start` 命令,则是希望 upstart 来以后台守护进程形式启动 `nginx` 服务。而刚才说了 `CMD service nginx start` 会被理解为 `CMD [ "sh", "-c", "service nginx start"]`,因此主进程实际上是 `sh`。那么当 `service nginx start` 命令结束后,`sh` 也就结束了,`sh` 作为主进程退出了,自然就会令容器退出。
|
||||
而使用 `service nginx start` 命令,则是希望 init 系统以后台守护进程的形式启动 nginx 服务。而刚才说了 `CMD service nginx start` 会被理解为 `CMD [ "sh", "-c", "service nginx start"]`,因此主进程实际上是 `sh`。那么当 `service nginx start` 命令结束后,`sh` 也就结束了,`sh` 作为主进程退出了,自然就会令容器退出。
|
||||
|
||||
正确的做法是直接执行 `nginx` 可执行文件,并且要求以前台形式运行。比如:
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# 参考文档
|
||||
|
||||
* `Dockerfie` 官方文档:https://docs.docker.com/engine/reference/builder/
|
||||
* `Dockerfile` 官方文档:https://docs.docker.com/engine/reference/builder/
|
||||
|
||||
* `Dockerfile` 最佳实践文档:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
|
||||
|
||||
|
@ -35,7 +35,8 @@ WORKDIR /go/src/github.com/go/helloworld/
|
||||
|
||||
COPY app.go .
|
||||
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql \
|
||||
RUN go mod init helloworld \
|
||||
&& go get -d -v github.com/go-sql-driver/mysql \
|
||||
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . \
|
||||
&& cp /go/src/github.com/go/helloworld/app /root
|
||||
|
||||
|
@ -61,7 +61,7 @@ FROM node:alpine as frontend
|
||||
COPY package.json /app/
|
||||
|
||||
RUN set -x ; cd /app \
|
||||
&& npm install --registry=https://registry.npm.taobao.org
|
||||
&& npm install --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY webpack.mix.js webpack.config.js tailwind.config.js /app/
|
||||
COPY resources/ /app/resources/
|
||||
@ -179,7 +179,7 @@ FROM node:alpine as frontend
|
||||
COPY package.json /app/
|
||||
|
||||
RUN set -x ; cd /app \
|
||||
&& npm install --registry=https://registry.npm.taobao.org
|
||||
&& npm install --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY webpack.mix.js webpack.config.js tailwind.config.js /app/
|
||||
COPY resources/ /app/resources/
|
||||
|
@ -65,7 +65,7 @@ $ echo \
|
||||
|
||||
```
|
||||
|
||||
>以上命令会添加稳定版本的 Docker APT 源,如果需要测试版本的 Docker 请将 stable 改为 test。
|
||||
>以上命令会添加稳定版本的 Docker APT 源,如果需要测试版本的 Docker 请将 stable 改为 test。 Debian11可能不使用`/etc/apt/keyrings/`, 如gpg错误可以考虑更换为`/etc/apt/trusted.gpg.d`, 见[issue 15727](https://github.com/docker/docs/issues/15727)。
|
||||
|
||||
### 安装 Docker
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
## 系统要求
|
||||
|
||||
[Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/) 要求系统最低为 macOS Mojave 10.14。
|
||||
[Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/) 要求系统最低为 macOS 必须是 10.15 或更高版本, Catalina、Big Sur 或者 Monterey,建议升级到最新版本的 macOS。
|
||||
|
||||
## 安装
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
# 镜像加速器
|
||||
|
||||
国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。国内很多云服务商都提供了国内加速器服务,例如:
|
||||
国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。~~国内很多云服务商都提供了国内加速器服务,例如:~~
|
||||
|
||||
* [阿里云加速器(点击管理控制台 -> 登录账号(淘宝账号) -> 右侧镜像工具 -> 镜像加速器 -> 复制加速器地址)](https://www.aliyun.com/product/acr?source=5176.11533457&userCode=8lx5zmtu)
|
||||
* [网易云加速器 `https://hub-mirror.c.163.com`](https://www.163yun.com/help/documents/56918246390157312)
|
||||
* [百度云加速器 `https://mirror.baidubce.com`](https://cloud.baidu.com/doc/CCE/s/Yjxppt74z#%E4%BD%BF%E7%94%A8dockerhub%E5%8A%A0%E9%80%9F%E5%99%A8)
|
||||
* [阿里云加速器(点击管理控制台 -> 登录账号(淘宝账号) -> 左侧镜像工具 -> 镜像加速器 -> 复制加速器地址)](https://cr.console.aliyun.com/cn-hangzhou/instances)
|
||||
|
||||
**由于镜像服务可能出现宕机,建议同时配置多个镜像。各个镜像站测试结果请到 [docker-practice/docker-registry-cn-mirror-test](https://github.com/docker-practice/docker-registry-cn-mirror-test/actions) 查看。**
|
||||
|
||||
> 国内各大云服务商(腾讯云、阿里云、百度云)均提供了 Docker 镜像加速服务,建议根据运行 Docker 的云平台选择对应的镜像加速服务,具体请参考本页最后一小节。
|
||||
|
||||
本节我们以 [网易云](https://www.163yun.com/) 镜像服务 `https://hub-mirror.c.163.com` 为例进行介绍。
|
||||
本节我们以 [AtomHub 可信镜像中心](https://hub.atomgit.com/) 镜像服务 `https://hub.atomgit.com` 为例进行介绍。
|
||||
|
||||
> `hub.atomgit.com` 仅包含部分官方镜像,可以满足初学者的使用。
|
||||
|
||||
## Ubuntu 16.04+、Debian 8+、CentOS 7+
|
||||
|
||||
@ -29,8 +29,7 @@ $ systemctl cat docker | grep '\-\-registry\-mirror'
|
||||
```json
|
||||
{
|
||||
"registry-mirrors": [
|
||||
"https://hub-mirror.c.163.com",
|
||||
"https://mirror.baidubce.com"
|
||||
"https://hub.atomgit.com"
|
||||
]
|
||||
}
|
||||
```
|
||||
@ -46,26 +45,24 @@ $ sudo systemctl restart docker
|
||||
|
||||
## Windows 10
|
||||
|
||||
对于使用 `Windows 10` 的用户,在任务栏托盘 Docker 图标内右键菜单选择 `Settings`,打开配置窗口后在左侧导航菜单选择 `Docker Engine`,在右侧像下边一样编辑 json 文件,之后点击 `Apply & Restart` 保存后 Docker 就会重启并应用配置的镜像地址了。
|
||||
对于使用 `Windows 10` 的用户,在任务栏托盘 Docker 图标内右键菜单选择 `Change settings`,打开配置窗口后在左侧导航菜单选择 `Docker Engine`,在右侧像下边一样编辑 json 文件,之后点击 `Apply & Restart` 保存后 Docker 就会重启并应用配置的镜像地址了。
|
||||
|
||||
```json
|
||||
{
|
||||
"registry-mirrors": [
|
||||
"https://hub-mirror.c.163.com",
|
||||
"https://mirror.baidubce.com"
|
||||
"https://hub.atomgit.com"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## macOS
|
||||
|
||||
对于使用 macOS 的用户,在任务栏点击 Docker Desktop 应用图标 -> `Perferences`,在左侧导航菜单选择 `Docker Engine`,在右侧像下边一样编辑 json 文件。修改完成之后,点击 `Apply & Restart` 按钮,Docker 就会重启并应用配置的镜像地址了。
|
||||
对于使用 macOS 的用户,在任务栏点击 Docker Desktop 应用图标 -> `Settings...`,在左侧导航菜单选择 `Docker Engine`,在右侧像下边一样编辑 json 文件。修改完成之后,点击 `Apply & restart` 按钮,Docker 就会重启并应用配置的镜像地址了。
|
||||
|
||||
```json
|
||||
{
|
||||
"registry-mirrors": [
|
||||
"https://hub-mirror.c.163.com",
|
||||
"https://mirror.baidubce.com"
|
||||
"https://hub.atomgit.com"
|
||||
]
|
||||
}
|
||||
```
|
||||
@ -76,7 +73,7 @@ $ sudo systemctl restart docker
|
||||
|
||||
```bash
|
||||
Registry Mirrors:
|
||||
https://hub-mirror.c.163.com/
|
||||
https://hub.atomgit.com/
|
||||
```
|
||||
|
||||
## `k8s.gcr.io` 镜像
|
||||
@ -100,6 +97,8 @@ $ docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/xxx
|
||||
* https://dockerhub.azk8s.cn **已转为私有**
|
||||
* https://reg-mirror.qiniu.com
|
||||
* https://registry.docker-cn.com
|
||||
* https://hub-mirror.c.163.com
|
||||
* https://mirror.baidubce.com
|
||||
|
||||
建议 **watch(页面右上角)** [镜像测试](https://github.com/docker-practice/docker-registry-cn-mirror-test) 这个 GitHub 仓库,我们会在此更新各个镜像地址的状态。
|
||||
|
||||
|
@ -32,7 +32,7 @@ sudo yum list docker-ce --showduplicates|sort -r
|
||||
|
||||
Loading mirror speeds from cached hostfile
|
||||
Loaded plugins: fastestmirror
|
||||
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
|
||||
docker-ce.x86_64 24.0.4-1.el7 docker-ce-stable
|
||||
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
|
||||
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
|
||||
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
|
||||
@ -46,7 +46,7 @@ docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
|
||||
#### 下载到指定文件夹(A)
|
||||
|
||||
```bash
|
||||
sudo yum install --downloadonly --downloaddir=/tmp/docker-19.03 docker-ce-19.03.8-3.el7 docker-ce-cli-19.03.8-3.el7
|
||||
sudo yum install --downloadonly --downloaddir=/tmp/docker24_offline_install/ docker-ce-24.0.4-1.el7 docker-ce-cli-24.0.4-1.el7
|
||||
```
|
||||
|
||||
```bash
|
||||
@ -56,11 +56,11 @@ Dependencies Resolved
|
||||
Package Arch Version Repository Size
|
||||
====================================================================================================================================================================================
|
||||
Installing:
|
||||
docker-ce x86_64 3:19.03.8-3.el7 docker 25 M
|
||||
docker-ce x86_64 24.0.4-1.el7 docker 25 M
|
||||
Installing for dependencies:
|
||||
container-selinux noarch 2:2.107-3.el7 extras 39 k
|
||||
containerd.io x86_64 1.2.13-3.1.el7 docker 23 M
|
||||
docker-ce-cli x86_64 1:19.03.8-3.el7 docker 40 M
|
||||
container-selinux noarch 24.0.4-1.el7 extras 39 k
|
||||
containerd.io x86_64 24.0.4-1.el7 docker 23 M
|
||||
docker-ce-cli x86_64 24.0.4-1.el7 docker 40 M
|
||||
|
||||
Transaction Summary
|
||||
====================================================================================================================================================================================
|
||||
@ -69,18 +69,19 @@ Install 1 Package (+3 Dependent packages)
|
||||
Total download size: 87 M
|
||||
Installed size: 363 M
|
||||
Background downloading packages, then exiting:
|
||||
(1/4): container-selinux-2.107-3.el7.noarch.rpm | 39 kB 00:00:00
|
||||
(2/4): containerd.io-1.2.13-3.1.el7.x86_64.rpm | 23 MB 00:00:00
|
||||
(3/4): docker-ce-19.03.8-3.el7.x86_64.rpm | 25 MB 00:00:00
|
||||
(4/4): docker-ce-cli-19.03.8-3.el7.x86_64.rpm | 40 MB 00:00:00
|
||||
(1/4): container-selinux-24.0.4-1.el7.noarch.rpm | 39 kB 00:00:00
|
||||
(2/4): containerd.io-24.0.4-1.el7.x86_64.rpm | 23 MB 00:00:00
|
||||
(3/4): docker-ce-24.0.4-1.el7.x86_64.rpm | 25 MB 00:00:00
|
||||
(4/4): docker-ce-cli-24.0.4-1.el7.x86_64.rpm | 40 MB 00:00:00
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Total 118 MB/s | 87 MB 00:00:00
|
||||
exiting because "Download Only" specified
|
||||
```
|
||||
#### 复制到目标服务器之后进入文件夹安装(C-N)
|
||||
|
||||
* 离线安装时,必须使用rpm命令不检查依赖的方式安装
|
||||
```bash
|
||||
yum install *.rpm
|
||||
rpm -Uvh *.rpm --nodeps --force
|
||||
```
|
||||
|
||||
#### 锁定软件版本(C-N)
|
||||
@ -105,7 +106,7 @@ sudo yum versionlock list
|
||||
|
||||
```bash
|
||||
Loaded plugins: fastestmirror, versionlock
|
||||
3:docker-ce-18.09.9-3.el7.*
|
||||
3:docker-ce-24.0.4-1.el7.*
|
||||
versionlock list done
|
||||
```
|
||||
|
||||
@ -116,7 +117,7 @@ sudo yum install docker-ce
|
||||
Loaded plugins: fastestmirror, versionlock
|
||||
Loading mirror speeds from cached hostfile
|
||||
Excluding 1 update due to versionlock (use "yum versionlock status" to show it)
|
||||
Package 3:docker-ce-18.09.9-3.el7.x86_64 already installed and latest version
|
||||
Package 3:docker-ce-24.0.4-1.el7.x86_64 already installed and latest version
|
||||
Nothing to do
|
||||
```
|
||||
|
||||
@ -128,7 +129,7 @@ sudo yum versionlock delete docker-ce
|
||||
|
||||
```bash
|
||||
Loaded plugins: fastestmirror, versionlock
|
||||
Deleting versionlock for: 3:docker-ce-18.09.9-3.el7.*
|
||||
Deleting versionlock for: 3:docker-ce-24.0.4-1.el7.*
|
||||
versionlock deleted: 1
|
||||
```
|
||||
|
||||
@ -246,4 +247,3 @@ sudo systemctl enable docker
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
@ -9,6 +9,8 @@ Docker 不仅支持 `x86_64` 架构的计算机,同时也支持 `ARM` 架构
|
||||
Docker 支持以下版本的 [Raspberry Pi OS](https://www.raspberrypi.org/software/operating-systems/) 操作系统:
|
||||
|
||||
* Raspberry Pi OS Buster
|
||||
* Raspberry Pi OS Bullseye
|
||||
* Raspberry Pi OS Bookworm
|
||||
|
||||
*注:* `Raspberry Pi OS` 由树莓派的开发与维护机构 [树莓派基金会](https://www.raspberrypi.org/) 官方支持,并推荐用作树莓派的首选系统,其基于 `Debian`。
|
||||
|
||||
@ -58,6 +60,33 @@ $ sudo add-apt-repository \
|
||||
|
||||
>以上命令会添加稳定版本的 Docker APT 源,如果需要测试版本的 Docker 请将 stable 改为 test。
|
||||
|
||||
#### 报错解决办法
|
||||
|
||||
在 `Raspberry Pi OS Bullseye/Bookworm` 中,添加 Docker 软件源的步骤可能会出现如下报错:
|
||||
|
||||
```bash
|
||||
Traceback (most recent call last):
|
||||
File "/usr/bin/add-apt-repository", line 95, in <module>
|
||||
sp = SoftwareProperties(options=options)
|
||||
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 109, in __init__
|
||||
self.reload_sourceslist()
|
||||
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 599, in reload_sourceslist
|
||||
self.distro.get_sources(self.sourceslist)
|
||||
File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 91, in get_sources
|
||||
raise NoDistroTemplateException(
|
||||
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/bullseye
|
||||
```
|
||||
|
||||
通过以下命令手动添加镜像源到 `/etc/apt/sources.list` 文件中即可解决:
|
||||
|
||||
```bash
|
||||
$ sudo echo "deb [arch=armhf] https://mirrors.aliyun.com/docker-ce/linux/raspbian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list
|
||||
|
||||
|
||||
# 官方源
|
||||
# $ sudo echo "deb [arch=armhf] https://download.docker.com/linux/raspbian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list
|
||||
```
|
||||
|
||||
### 安装 Docker
|
||||
|
||||
更新 apt 软件包缓存,并安装 `docker-ce`。
|
||||
|
@ -6,23 +6,31 @@
|
||||
|
||||
### 系统要求
|
||||
|
||||
Docker 支持以下版本的 [Ubuntu](https://ubuntu.com/server) 操作系统:
|
||||
Docker 支持诸多版本的 [Ubuntu](https://ubuntu.com/server) 操作系统。但是较旧的版本上将不会有Docker新版本的持续更新,以截至2024年中的几个 Ubuntu LTS(Long Term Support,长期支持)版本为例:
|
||||
|
||||
* Ubuntu Hirsute 21.04
|
||||
* Ubuntu Groovy 20.10
|
||||
* Ubuntu Focal 20.04 (LTS)
|
||||
* Ubuntu Bionic 18.04 (LTS)
|
||||
* Ubuntu Noble 24.04 (LTS),Docker v27.2.1
|
||||
* Ubuntu Jammy 22.04 (LTS), Docker v27.2.1
|
||||
* Ubuntu Focal 20.04 (LTS), Docker v27.2.1
|
||||
* Ubuntu Bionic 18.04 (LTS),Docker v24.0.2
|
||||
|
||||
Docker 可以安装在 64 位的 x86 平台或 ARM 平台上。Ubuntu 发行版中,LTS(Long-Term-Support)长期支持版本,会获得 5 年的升级维护支持,这样的版本会更稳定,因此在生产环境中推荐使用 LTS 版本。
|
||||
在 Ubuntu LTS 版本上,目前 Docker 支持 amd64、arm64、armhf、ppc64el、s390x 等 5 个平台;而非 LTS 版本支持的平台通常较少。同时,LTS 版本会获得 5 年的升级维护支持,这样的系统会获得更长期的安全保障,因此在生产环境中推荐使用 LTS 版本。
|
||||
|
||||
### 卸载旧版本
|
||||
|
||||
旧版本的 Docker 称为 `docker` 或者 `docker-engine`,使用以下命令卸载旧版本:
|
||||
|
||||
```bash
|
||||
$ sudo apt-get remove docker \
|
||||
docker-engine \
|
||||
docker.io
|
||||
$ for pkg in docker \
|
||||
docker-engine \
|
||||
docker.io \
|
||||
docker-doc \
|
||||
docker-compose \
|
||||
podman-docker \
|
||||
containerd \
|
||||
runc;
|
||||
do
|
||||
sudo apt remove $pkg;
|
||||
done
|
||||
```
|
||||
|
||||
## 使用 APT 安装
|
||||
@ -30,9 +38,9 @@ $ sudo apt-get remove docker \
|
||||
由于 `apt` 源使用 HTTPS 以确保软件下载过程中不被篡改。因此,我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书。
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt update
|
||||
|
||||
$ sudo apt-get install \
|
||||
$ sudo apt install \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
@ -73,9 +81,9 @@ $ echo \
|
||||
更新 apt 软件包缓存,并安装 `docker-ce`:
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt update
|
||||
|
||||
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
|
||||
$ sudo apt install docker-ce docker-ce-cli containerd.io
|
||||
```
|
||||
|
||||
## 使用脚本自动安装
|
||||
|
@ -62,7 +62,7 @@ Kubernetes 校验节点可用依赖于 ID。在当前的版本中,有两个接
|
||||
* 集群范围内节点同步
|
||||
* 单节点生命周期管理
|
||||
|
||||
节点控制有一个同步轮寻,主要监听所有云平台的虚拟实例,会根据节点状态创建和删除。可以通过 `--node_sync_period`标志来控制该轮寻。如果一个实例已经创建,节点控制将会为其创建一个结构。同样的,如果一个节点被删除,节点控制也会删除该结构。在 Kubernetes 启动时可用通过 `--machines`标记来显示指定节点。同样可以使用 `kubectl` 来一条一条的添加节点,两者是相同的。通过设置 `--sync_nodes=false`标记来禁止集群之间的节点同步,你也可以使用 api/kubectl 命令行来增删节点。
|
||||
节点控制有一个同步轮询,主要监听所有云平台的虚拟实例,会根据节点状态创建和删除。可以通过 `--node_sync_period`标志来控制该轮询。如果一个实例已经创建,节点控制将会为其创建一个结构。同样的,如果一个节点被删除,节点控制也会删除该结构。在 Kubernetes 启动时可用通过 `--machines`标记来显示指定节点。同样可以使用 `kubectl` 来一条一条的添加节点,两者是相同的。通过设置 `--sync_nodes=false`标记来禁止集群之间的节点同步,你也可以使用 api/kubectl 命令行来增删节点。
|
||||
|
||||
## 容器组
|
||||
|
||||
|
@ -75,9 +75,9 @@ username/ubuntu
|
||||
|
||||
## 自动构建
|
||||
|
||||
> 2021 年 6 月 18 日之后,该项功能仅限[付费用户](https://www.docker.com/blog/changes-to-docker-hub-autobuilds/)使用。
|
||||
> 2021 年 7 月 26 日之后,该项功能仅限[付费用户](https://www.docker.com/blog/changes-to-docker-hub-autobuilds/)使用。
|
||||
|
||||
自动构建(`Automated Builds`)功能对于需要经常升级镜像内程序来说,十分方便。
|
||||
自动构建(`Automated Builds`)可以自动触发构建镜像,方便升级镜像。
|
||||
|
||||
有时候,用户构建了镜像,安装了某个软件,当软件发布新版本则需要手动更新镜像。
|
||||
|
||||
|
@ -103,7 +103,7 @@ REPOSITORY TAG IMAGE ID CREAT
|
||||
|
||||
```json
|
||||
{
|
||||
"registry-mirror": [
|
||||
"registry-mirrors": [
|
||||
"https://hub-mirror.c.163.com",
|
||||
"https://mirror.baidubce.com"
|
||||
],
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
来自 Docker 官网的这张图片形象的展示了集群中管理节点与工作节点的关系。
|
||||
|
||||

|
||||

|
||||
|
||||
## 服务和任务
|
||||
|
||||
@ -32,4 +32,4 @@
|
||||
|
||||
来自 Docker 官网的这张图片形象的展示了容器、任务、服务的关系。
|
||||
|
||||

|
||||

|
||||
|
@ -62,7 +62,7 @@ $ docker service create \
|
||||
--network mysql_private \
|
||||
--publish target=30000,port=80 \
|
||||
--mount type=volume,source=wpdata,destination=/var/www/html \
|
||||
--secret source=mysql_password,target=wp_db_password,mode=0400 \
|
||||
--secret source=mysql_password,target=wp_db_password,mode=0444 \
|
||||
-e WORDPRESS_DB_USER="wordpress" \
|
||||
-e WORDPRESS_DB_PASSWORD_FILE="/run/secrets/wp_db_password" \
|
||||
-e WORDPRESS_DB_HOST="mysql:3306" \
|
||||
|
Loading…
x
Reference in New Issue
Block a user