synchronization
This commit is contained in:
359
Docker/Builder/Buildkit/README.md
Normal file
359
Docker/Builder/Buildkit/README.md
Normal file
@@ -0,0 +1,359 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Buildkit构建镜像
|
||||
|
||||
## 最小化使用 Buildkit 构建镜像
|
||||
|
||||
1. 修改 docker 守护进程配置
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
2. 加入
|
||||
|
||||
```bash
|
||||
{
|
||||
"features": {
|
||||
"buildkit": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
重载 docker
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload && systemctl reload docker
|
||||
```
|
||||
|
||||
> 如果报错提示需要安装 Buildx , 则查看 [BUILDX安装](https://gitee.com/offends/Kubernetes/tree/main/Docker/Builder/Buildx/README.md) 安装一下
|
||||
|
||||
3. 构建镜像
|
||||
|
||||
```bash
|
||||
DOCKER_BUILDKIT=1 docker build --no-cache -t app:v1 .
|
||||
```
|
||||
|
||||
|
||||
## 使用完全体 Buildkit 构建镜像
|
||||
|
||||
[官方文档](https://docs.docker.com/build/buildkit/)
|
||||
|
||||
### 安装
|
||||
|
||||
1. 克隆代码
|
||||
|
||||
```bash
|
||||
git clone https://gitee.com/offends/Kubernetes.git
|
||||
cd Kubernetes/Docker/Builder/Buildkit
|
||||
```
|
||||
|
||||
2. 安装 Buildkit
|
||||
|
||||
> 这里使用 . 执行脚本否则需要手动执行 `source /etc/profile`
|
||||
|
||||
```bash
|
||||
. install.sh
|
||||
```
|
||||
|
||||
3. 安装 Buildx(非必选, 如果不希望安装Buildx, 则直接看文档"基础命令"部分来构建镜像)
|
||||
|
||||
查看此文档: [BUILDX安装](https://gitee.com/offends/Kubernetes/tree/main/Docker/Builder/Buildx/README.md)
|
||||
|
||||
### Dockerfile 写法介绍
|
||||
|
||||
> Dockerfile `# syntax = docker/dockerfile:<声明>` 是必加的
|
||||
|
||||
[官方文档](https://docs.docker.com/build/dockerfile/frontend/#custom-dockerfile-syntax)
|
||||
|
||||
1. `# syntax=docker/dockerfile:1`:
|
||||
|
||||
这个指令指定了 Dockerfile 使用的语法版本。在这个例子中,`:1` 表示使用 Dockerfile 的第一个版本。这个版本引入了基本的 Dockerfile 功能,是最基础的语法规则。它是 Dockerfile 的最低版本,提供了最基本的指令和结构,不包含较新的特性。
|
||||
|
||||
2. `# syntax = docker/dockerfile:experimental`:
|
||||
|
||||
这个语法声明告诉 Docker 使用实验性特性来解析 Dockerfile。`experimental` 标记引入了一些实验性的功能,可能包含一些不稳定或尚未广泛测试的功能,允许使用一些较新的、可能还不是标准的 Dockerfile 特性。使用这个标记可以在 Dockerfile 中尝试新的、实验性的功能。
|
||||
|
||||
### 挂载缓存目录 cache
|
||||
|
||||
> 这里是通过存储 Docker 缓存当中实现的,咱们通过两次构建演示过程
|
||||
|
||||
1. 编写 Dockerfile
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
- 第一次构建
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine
|
||||
|
||||
RUN --mount=type=cache,target=/data,id=file_dir,sharing=locked \
|
||||
echo "hello" >> /data/file.txt
|
||||
```
|
||||
|
||||
- 第二次构建
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine
|
||||
|
||||
RUN --mount=type=cache,target=/data,id=file_dir,sharing=locked \
|
||||
echo "hello-2" >> /data/file.txt; \
|
||||
cp /data/file.txt /
|
||||
```
|
||||
|
||||
2. 开始构建
|
||||
|
||||
```bash
|
||||
docker build -t app:v1 .
|
||||
```
|
||||
|
||||
3. 检查结果
|
||||
|
||||
```bash
|
||||
docker run -it --rm app:v1 sh
|
||||
cat file.txt
|
||||
```
|
||||
|
||||
> 发现有两行内容则代表容器第二次构建已经使用到缓存了
|
||||
|
||||
**参数解释**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| ------- | --------------------------------------------------- |
|
||||
| id | 用于标识不同缓存的可选ID。默认为目标值。 |
|
||||
| target1 | 挂载路径。 |
|
||||
| ro | 如果设置,只读。 |
|
||||
| sharing | 其中一个 shared、private 或 locked。默认为 shared。 |
|
||||
| from | 用作缓存挂载基础的构建阶段。默认为空目录。 |
|
||||
| source | 要挂载的源自 from 的子路径。默认为 from 的根目录。 |
|
||||
| mode | 新缓存目录的文件模式(八进制)。默认为 0755。 |
|
||||
| uid | 新缓存目录的用户ID。默认为 0。 |
|
||||
| gid | 新缓存目录的组ID。默认为 0。 |
|
||||
|
||||
**sharing参数**
|
||||
|
||||
1. **Shared (shared)**: 这是默认设置。在共享模式下,多个写入者可以同时使用相同的缓存挂载。这意味着多个构建可以同时读取和写入缓存数据。
|
||||
2. **Private (private)**: 当设置为私有模式时,如果存在多个写入者,它会为每个写入者创建一个新的挂载。这样可以避免并发写入的冲突,但也可能导致存储空间的浪费。
|
||||
3. **Locked (locked)**: 锁定模式会暂停第二个写入者的操作,直到第一个写入者释放挂载。这确保了在任何给定时刻只有一个写入者能够访问缓存挂载,从而避免了并发写入的问题,但也可能导致构建延迟。
|
||||
|
||||
### 挂载文件 bind
|
||||
|
||||
> 将一个镜像或上一构建阶段的文件挂载到指定位置
|
||||
|
||||
1. 编写 Dockerfile
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine AS builder
|
||||
|
||||
RUN apk add git \
|
||||
&& git clone https://gitee.com/offends/Docs.git \
|
||||
&& tar -cvf Docker-Template.tar ./Docker-Template
|
||||
|
||||
FROM alpine
|
||||
|
||||
# 挂载上一构建阶段文件
|
||||
RUN --mount=type=bind,from=builder,source=/Docker-Template.tar,target=/Docker-Template.tar \
|
||||
cp /Docker-Template.tar /Docker-Template.tar.bak
|
||||
|
||||
# 挂载另一个镜像的文件
|
||||
RUN --mount=type=bind,from=nginx:alpine-slim,source=/etc/nginx/nginx.conf,target=/nginx.conf \
|
||||
cp /nginx.conf /nginx.conf.bak
|
||||
```
|
||||
|
||||
2. 开始构建
|
||||
|
||||
```bash
|
||||
docker build -t app:v1 .
|
||||
```
|
||||
|
||||
3. 检查结果
|
||||
|
||||
```bash
|
||||
docker run -it --rm app:v1 sh
|
||||
ls
|
||||
```
|
||||
|
||||
> / 目录下存在 nginx.conf.bak 和 Docker-Template.tar.bak 则代表成功
|
||||
|
||||
### 挂载文件系统 tmpfs
|
||||
|
||||
> 将文件系统挂载到指定位置
|
||||
|
||||
1. 编写 Dockerfile
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine
|
||||
|
||||
RUN --mount=type=tmpfs,size=100m,target=/temp \
|
||||
echo "hello" > /temp/file.txt
|
||||
```
|
||||
|
||||
2. 开始构建
|
||||
|
||||
```bash
|
||||
docker build -t app:v1 .
|
||||
```
|
||||
|
||||
3. 检查结果
|
||||
|
||||
```bash
|
||||
docker run -it --rm app:v1 sh
|
||||
ls /temp
|
||||
```
|
||||
|
||||
> 没有文件则正确,因为在 RUN 执行完命令之后挂载的文件系统将会被卸载
|
||||
|
||||
### 加密内容管理
|
||||
|
||||
> 为了更好的看到效果我们拿创建目录 hello-file 举例
|
||||
|
||||
#### 示例一(加密文件挂载)
|
||||
|
||||
[官网文档](https://docs.docker.com/engine/reference/builder/#run---mounttypesecret)
|
||||
|
||||
1. 编写挂载文件
|
||||
|
||||
```bash
|
||||
cat > file_secret <<EOF
|
||||
hello-file
|
||||
EOF
|
||||
```
|
||||
|
||||
2. 编写 Dockerfile
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine
|
||||
|
||||
RUN --mount=type=secret,id=file_secret,target=/run/secrets/file_secret \
|
||||
mkdir $(cat /run/secrets/file_secret)
|
||||
```
|
||||
|
||||
3. 开始构建
|
||||
|
||||
```bash
|
||||
docker build --no-cache --secret id=file_secret,src=./file_secret -t app:v1 .
|
||||
```
|
||||
|
||||
4. 检验结果
|
||||
|
||||
```bash
|
||||
docker run -it --rm app:v1 sh
|
||||
ls
|
||||
```
|
||||
|
||||
> 看到 / 下存在 hello-file 目录,并且挂载的 file_secret 也消失了,则代表加密内容已成功传入。
|
||||
|
||||
#### 示例二(加密变量传入)
|
||||
|
||||
[官网文档](https://docs.docker.com/engine/reference/commandline/buildx_build/#env)
|
||||
|
||||
1. 编写 Dockerfile
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine
|
||||
|
||||
RUN --mount=type=secret,id=env_secret,target=/run/secrets/env_secret \
|
||||
mkdir $(cat /run/secrets/env_secret)
|
||||
```
|
||||
|
||||
2. 开始构建
|
||||
|
||||
```bash
|
||||
env_secret=hello-file docker buildx build --no-cache --secret id=env_secret -t app:v1 --load .
|
||||
```
|
||||
|
||||
### SSH 密钥管理
|
||||
|
||||
[官网文档]()
|
||||
|
||||
> gitee 仓库举例
|
||||
|
||||
1. 编写 Dockerfile
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```dockerfile
|
||||
# syntax = docker/dockerfile:1
|
||||
FROM alpine
|
||||
|
||||
# 如果是Github 则使用 github.com
|
||||
RUN apk add --no-cache openssh-client git \
|
||||
&& mkdir -p -m 0600 ~/.ssh && ssh-keyscan gitee.com >> ~/.ssh/known_hosts
|
||||
|
||||
RUN --mount=type=ssh git clone git@gitee.com:offends/Docker.git
|
||||
```
|
||||
|
||||
2. 开始构建
|
||||
|
||||
```bash
|
||||
docker build --ssh default=~/.ssh/id_rsa -t app:v1 .
|
||||
```
|
||||
|
||||
# 基础命令
|
||||
|
||||
1. 清理缓存
|
||||
|
||||
```bash
|
||||
docker builder prune
|
||||
```
|
||||
|
||||
2. 构建镜像并打包
|
||||
|
||||
> 镜像不会存在于 docker images 内,用于单纯的打包最好不过了
|
||||
|
||||
```bash
|
||||
buildctl build \
|
||||
--frontend=dockerfile.v0 \
|
||||
--local context=. \
|
||||
--local dockerfile=. \
|
||||
--output type=docker,name=app:v1,dest=image.tar
|
||||
```
|
||||
|
||||
|
||||
**参数解释**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| ----------------------------------------------- | ------------------------------------------------------------ |
|
||||
| --frontend=dockerfile.v0 | 使用的构建前端,这里是 Dockerfile 的版本。 |
|
||||
| --local context=. | 指定本地上下文路径,即构建过程中使用的上下文路径(当前目录)。 |
|
||||
| --local dockerfile=. | 指定本地 Dockerfile 路径,即 Dockerfile 所在的路径(当前目录)。 |
|
||||
| --output type=docker,name=app:v1,dest=image.tar | 输出设置,指定输出的类型为 Docker 镜像(type=docker),镜像的名称为 app:v1(name=app:v1),输出目标为 image.tar 文件(dest=image.tar)。 |
|
||||
|
||||
|
||||
|
13
Docker/Builder/Buildkit/buildkitd.service
Normal file
13
Docker/Builder/Buildkit/buildkitd.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=buildkitd
|
||||
# 指定了在系统启动时该服务应该在 network.target 启动后才启动。这确保了服务在网络可用后才会被启动
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=/usr/local/buildkit/bin/buildkitd
|
||||
# ExecStart=/usr/local/bin/buildkitd --oci-worker=false --containerd-worker=true
|
||||
|
||||
[Install]
|
||||
# 指明了在系统进入 multi-user.target 时(通常是完全启动并准备好用户登录的状态)启用这个服务
|
||||
WantedBy=multi-user.target
|
10
Docker/Builder/Buildkit/buildkitd.toml
Normal file
10
Docker/Builder/Buildkit/buildkitd.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[worker.oci]
|
||||
gc = true
|
||||
gckeepstorage = 10000
|
||||
[[worker.oci.gcpolicy]]
|
||||
keepBytes = 512000000
|
||||
keepDuration = 172800
|
||||
filters = [ "type==source.local", "type==exec.cachemount", "type==source.git.checkout"]
|
||||
[[worker.oci.gcpolicy]]
|
||||
all = true
|
||||
keepBytes = 1024000000
|
60
Docker/Builder/Buildkit/install.sh
Normal file
60
Docker/Builder/Buildkit/install.sh
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 安装 Buildkit 脚本
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2023-12-05
|
||||
#############################################################################################
|
||||
|
||||
# 加载检测脚本
|
||||
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
||||
|
||||
function CHECK(){
|
||||
# 官方下载仓库: https://github.com/moby/buildkit/releases/
|
||||
VERSION="v0.12.4"
|
||||
DIR="/usr/local/buildkit"
|
||||
|
||||
URL="https://github.com/moby/buildkit/releases/download/$VERSION/buildkit-$VERSION.linux-$ARCH_TYPE_2.tar.gz"
|
||||
BIN_NAME="Buildkit"
|
||||
CHECK_BIN "$DIR/bin/buildctl"
|
||||
}
|
||||
|
||||
# 引用 check_bin 变量不存在则安装
|
||||
function CHECK_BIN_INSTALL(){
|
||||
if [ "$INSTALL_BIN" = false ]; then
|
||||
CHECK_INSTALL wget
|
||||
SEND_INFO "正在安装 $BIN_NAME,请稍后"
|
||||
CHECK_DIR "$DIR"
|
||||
CHECK_COMMAND_NULL wget $URL
|
||||
CHECK_COMMAND_NULL tar -xf buildkit-v*.linux-$ARCH_TYPE_2.tar.gz -C /usr/local/buildkit
|
||||
CHECK_COMMAND_NULL echo 'export PATH=/usr/local/buildkit/bin:$PATH' \>\> /etc/profile
|
||||
CHECK_COMMAND_NULL source /etc/profile
|
||||
CHECK_SYSTEMD_FILE
|
||||
CHECK_COMMAND_NULL systemctl daemon-reload
|
||||
CHECK_COMMAND_NULL systemctl enable --now buildkitd
|
||||
SEND_INFO "正在清理文件"
|
||||
CHECK_COMMAND_NULL rm -rf buildkit-v*.linux-$ARCH_TYPE_2.tar.gz
|
||||
SEND_INFO "$BIN_NAME 版本: $(buildkitd --version | grep -o 'v[0-9]\+\(\.[0-9]\+\)\{2\}')"
|
||||
|
||||
else
|
||||
SEND_INFO "$BIN_NAME 已安装"
|
||||
CHECK_SYSTEMD buildkitd
|
||||
SEND_INFO "$BIN_NAME 版本: $(buildkitd --version | grep -o 'v[0-9]\+\(\.[0-9]\+\)\{2\}')"
|
||||
fi
|
||||
}
|
||||
|
||||
# 官方 toml 参数文档: https://docs.docker.com/build/buildkit/toml-configuration/
|
||||
function CHECK_SYSTEMD_FILE(){
|
||||
CHECK_COMMAND_NULL \\cp ./buildkitd.service /usr/lib/systemd/system/buildkitd.service
|
||||
CHECK_DIR "/etc/buildkit/"
|
||||
CHECK_COMMAND_NULL \\cp ./buildkitd.toml /etc/buildkit/buildkitd.toml
|
||||
}
|
||||
|
||||
function ALL(){
|
||||
CHECK_SYSTEMD docker
|
||||
CHECK_CPU
|
||||
CHECK
|
||||
CHECK_BIN_INSTALL
|
||||
}
|
||||
|
||||
ALL
|
5
Docker/Builder/Buildx/Dockerfile
Normal file
5
Docker/Builder/Buildx/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM --platform=$TARGETPLATFORM alpine
|
||||
|
||||
RUN echo "Startup success" > /os.txt
|
||||
|
||||
CMD tail -f /os.txt
|
138
Docker/Builder/Buildx/README.md
Normal file
138
Docker/Builder/Buildx/README.md
Normal file
@@ -0,0 +1,138 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# BUILDX构建镜像
|
||||
|
||||
## 安装
|
||||
|
||||
1. 克隆代码
|
||||
|
||||
```bash
|
||||
git clone https://gitee.com/offends/Kubernetes.git
|
||||
cd Kubernetes/Docker/Builder/Buildx
|
||||
```
|
||||
|
||||
2. 安装
|
||||
|
||||
```bash
|
||||
./install.sh
|
||||
```
|
||||
|
||||
## 手动构建
|
||||
|
||||
1. 编写 Dockerfile
|
||||
|
||||
```dockerfile
|
||||
# vi Dockerfile
|
||||
FROM --platform=$TARGETPLATFORM alpine
|
||||
|
||||
RUN echo "Startup success" > /os.txt
|
||||
|
||||
CMD tail -f /os.txt
|
||||
```
|
||||
|
||||
2. 创建了一个名为 "buildx" 的构建器
|
||||
|
||||
```bash
|
||||
docker buildx create --use --name=buildx --driver docker-container --driver-opt image=moby/buildkit:buildx-stable-1
|
||||
```
|
||||
|
||||
**参数解释**
|
||||
|
||||
| 参数 | 说明 |
|
||||
| ------------------------------ | ------------------------------------------------------------ |
|
||||
| `--use` | 将新构建器设置为当前活动的构建器(默认构建器) |
|
||||
| `--name=buildx` | 指定新构建器的名称为 "buildx" |
|
||||
| `--driver docker` | 指定使用的驱动程序为 "docker" |
|
||||
| `--driver-opt image=...` | 指定驱动程序选项,此处是指定 BuildKit 镜像的位置为 "moby/buildkit:buildx-stable-1" |
|
||||
| `--config /etc/buildkitd.toml` | 指定配置文件 |
|
||||
|
||||
3. 构建多架构镜像并推送镜像仓库
|
||||
|
||||
**示例**
|
||||
|
||||
> 举例仓库地址为 "offends"
|
||||
|
||||
- 第一种方式(简单)
|
||||
|
||||
```bash
|
||||
docker buildx build --platform linux/amd64,linux/arm/v7 -t offends/app:v1 . --push
|
||||
```
|
||||
|
||||
- 第二种方式
|
||||
|
||||
```bash
|
||||
docker buildx build --platform linux/amd64,linux/arm/v7 -t offends/app:v1 --output type=registry,dest=offends .
|
||||
```
|
||||
|
||||
> 查看 buildx 当前可构建架构
|
||||
>
|
||||
> ```bash
|
||||
> docker buildx ls
|
||||
> ```
|
||||
|
||||
**参数解释**
|
||||
|
||||
| 参数 | 解释 |
|
||||
| -------------------------------------------- | ------------------------------------------------------------ |
|
||||
| `docker buildx build` | 执行 Buildx 构建的命令 |
|
||||
| `--platform linux/amd64,linux/arm/v6` | 指定要构建的目标平台,这里包括 Linux AMD64 和 ARMv6 |
|
||||
| `-t app:v1` | 为构建的镜像设置标签为 "app:v1" |
|
||||
| `-f ./Dockerfile` | 指定要使用的 Dockerfile 文件路径 |
|
||||
| `.` | 构建上下文的路径,表示当前目录是构建上下文,其中包含了构建镜像所需的文件和指令 |
|
||||
| `--output type=local,dest=.docker` | 指定输出类型为本地,并将构建结果输出到名为 `.docker` 的目录中 |
|
||||
| `--output type=oci,dest=<path>` | 将构建结果输出为 OCI 格式的镜像包,并保存到指定路径 |
|
||||
| `--output type=docker,dest=<path>` | 将构建结果输出为 Docker 格式的镜像包,并保存到指定路径 |
|
||||
| `--output type=image,name=<image_name>` | 将构建的镜像推送到指定的镜像仓库,指定镜像名称 |
|
||||
| `--output type=registry,dest=<registry_url>` | 将构建的镜像推送到指定的镜像仓库地址 |
|
||||
| `--push` | 将构建的镜像推送到指定的镜像仓库 |
|
||||
|
||||
### 常用命令
|
||||
|
||||
- 删除构建器
|
||||
|
||||
```bash
|
||||
docker buildx rm <构建器名称>
|
||||
```
|
||||
|
||||
- 设置默认构建器
|
||||
|
||||
```bash
|
||||
docker buildx use <构建器名称>
|
||||
```
|
||||
|
||||
- 检查 Docker Buildx 构建器的详细信息
|
||||
|
||||
```bash
|
||||
docker buildx inspect
|
||||
```
|
||||
|
||||
|
||||
|
||||
# 使用脚本构建镜像并推送仓库
|
||||
|
||||
> 前提条件:
|
||||
>
|
||||
> 1. 已安装 Buildx, 安装脚本: [BUILDX安装](https://gitee.com/offends/Kubernetes/tree/main/Docker/Builder/Buildx/README.md)
|
||||
>
|
||||
> 2. 登录一个可推送镜像的仓库
|
||||
>
|
||||
> ```bash
|
||||
> docker login <仓库地址> -u <用户名> -p<密码>
|
||||
> ```
|
||||
>
|
||||
> 3. 根据自己需求添加架构
|
||||
>
|
||||
> 4. 配置变量
|
||||
|
||||
```bash
|
||||
export PLATFORM="linux/amd64,linux/arm/v6"
|
||||
# 这里的仓库地址需要是一个可推送的镜像仓库才行,否则将推送失败
|
||||
export IMAGE_NAME=<仓库地址>/<镜像名>
|
||||
export IMAGE_TAG=<镜像标签>
|
||||
```
|
||||
|
||||
开始构建
|
||||
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
37
Docker/Builder/Buildx/build.sh
Normal file
37
Docker/Builder/Buildx/build.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 构建 Dockerfile 脚本
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2023-11-27
|
||||
#############################################################################################
|
||||
|
||||
# 加载检测脚本
|
||||
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
||||
|
||||
# 创建 buildx
|
||||
function CREATE_BUILDX(){
|
||||
# 国内镜像
|
||||
# --driver-opt dockerpracticesig/buildkit:master
|
||||
# --driver-opt dockerpracticesig/buildkit:master-tencent
|
||||
CHECK_COMMAND_NULL docker buildx create --use --name=buildx --driver docker-container --driver-opt image=moby/buildkit:buildx-stable-1
|
||||
CHECK_COMMAND_TRUE "创建 buildx 成功" "创建 buildx 失败,请根据错误信息检查"
|
||||
}
|
||||
|
||||
# 开始构建镜像
|
||||
function BUILD_IMAGE(){
|
||||
# 构建镜像
|
||||
CHECK_COMMAND_NULL docker buildx build --platform ${PLATFORM} -t ${IMAGE_NAME}:${IMAGE_TAG} . --push
|
||||
CHECK_COMMAND_TRUE "构建镜像成功" "构建镜像失败,请根据错误信息检查"
|
||||
NULL_TRUE docker buildx rm buildx
|
||||
GREEN_PRINTF "构建镜像完成,查看镜像架构信息: \n$(docker buildx imagetools inspect ${IMAGE_NAME}:${IMAGE_TAG} | grep Platform: | grep -v unknown/unknown | awk -F " " '{print $2}')"
|
||||
}
|
||||
|
||||
function ALL(){
|
||||
# 检测是否安装 Docker
|
||||
CHECK_SYSTEMD docker
|
||||
CREATE_BUILDX
|
||||
BUILD_IMAGE
|
||||
}
|
||||
|
||||
ALL
|
60
Docker/Builder/Buildx/install.sh
Normal file
60
Docker/Builder/Buildx/install.sh
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 安装 Buildx 脚本
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2023-11-27
|
||||
#############################################################################################
|
||||
|
||||
# 加载检测脚本
|
||||
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
||||
|
||||
function CHECK(){
|
||||
# 官方下载仓库: https://github.com/docker/buildx/releases
|
||||
VERSION="v0.12.0"
|
||||
DIR="/root/.docker/cli-plugins"
|
||||
|
||||
URL="https://github.com/docker/buildx/releases/download/$VERSION/buildx-$VERSION.linux-$ARCH_TYPE_2"
|
||||
BIN_NAME="Buildx"
|
||||
CHECK_BIN "$DIR/docker-buildx"
|
||||
}
|
||||
|
||||
# 引用 check_bin 变量不存在则安装
|
||||
function CHECK_BIN_INSTALL(){
|
||||
if [ "$INSTALL_BIN" = false ]; then
|
||||
CHECK_INSTALL wget
|
||||
SEND_INFO "正在安装 $BIN_NAME,请稍后"
|
||||
CHECK_DIR "$DIR"
|
||||
CHECK_COMMAND_NULL wget $URL
|
||||
CHECK_COMMAND_NULL mv buildx-v*.linux-amd64 ~/.docker/cli-plugins/docker-buildx
|
||||
CHECK_COMMAND_NULL chmod +x ~/.docker/cli-plugins/docker-buildx
|
||||
SEND_INFO "Buildx 版本: $(docker buildx version | awk '{print $2}')"
|
||||
|
||||
else
|
||||
SEND_INFO "$BIN_NAME 已安装"
|
||||
SEND_INFO "Buildx 版本: $(docker buildx version | awk '{print $2}')"
|
||||
fi
|
||||
}
|
||||
|
||||
# function CHECK_BIN_INSTALL_MAN(){
|
||||
# export DOCKER_BUILDKIT=1
|
||||
# docker build --platform=local -o . git://github.com/docker/buildx
|
||||
# }
|
||||
|
||||
# 添加模拟架构
|
||||
function RUN_BINFMT(){
|
||||
SEND_INFO "正在添加模拟架构"
|
||||
CHECK_COMMAND_NULL docker run --privileged --rm tonistiigi/binfmt --install all
|
||||
SEND_INFO "添加模拟架构完成,查看架构信息: docker buildx ls"
|
||||
}
|
||||
|
||||
function ALL(){
|
||||
CHECK_SYSTEMD docker
|
||||
CHECK_CPU
|
||||
CHECK
|
||||
CHECK_BIN_INSTALL
|
||||
CHECK_CORE
|
||||
RUN_BINFMT
|
||||
}
|
||||
|
||||
ALL
|
35
Docker/Compose/Docs/Docker-Compose容器安全配置.md
Normal file
35
Docker/Compose/Docs/Docker-Compose容器安全配置.md
Normal file
@@ -0,0 +1,35 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker-Compose容器安全配置
|
||||
|
||||
- **security_opt**
|
||||
|
||||
`security_opt` 选项用于调整容器的安全配置。这个选项允许管理员覆盖或增加默认的安全设置,提供了更多的安全控制。其中一个常见的用途是 `no-new-privileges` 标志。no-new-privileges: 设置为 `true` 时,这个标志阻止容器获取任何新的权限。这意味着即使容器内的应用或用户尝试通过如 `setuid` 等方式提升权限,也会被系统阻止。这是一个防止权限提升攻击的重要安全措施。例如,如果一个容器运行的应用被攻破,攻击者将不能通过提升权限来进一步控制宿主机或其他容器。
|
||||
|
||||
**示例**
|
||||
|
||||
```bash
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
container_name: nginx
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
```
|
||||
|
||||
- **cap_drop**
|
||||
|
||||
`cap_drop` 选项用于删除容器的Linux能力。Linux能力是一种精细控制权限的机制,它允许将传统的root权限分解为更小的单元,每个单元控制一个特定的权限。ALL: 使用 `cap_drop: - ALL` 表示放弃所有预定义的能力。这将限制容器内进程的权限,即使它以 root 用户运行,也不能执行某些特权操作,例如修改系统文件、更改网络配置等。这种做法最大限度地减少了容器被滥用的风险,并增加了攻击者通过容器获得宿主机控制权的难度。
|
||||
|
||||
**示例**
|
||||
|
||||
```bash
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
container_name: nginx
|
||||
cap_drop:
|
||||
- ALL
|
||||
```
|
||||
|
||||
通过使用这些选项,Docker管理员可以显著提升容器的安全性,避免容器成为攻击者突破系统安全的突破口。这些措施尤其适用于运行不信任的代码或在多租户环境中运行的容器。
|
111
Docker/Compose/Docs/Docker-Compose部署Simplex服务器SMPXFTP服务.md
Normal file
111
Docker/Compose/Docs/Docker-Compose部署Simplex服务器SMPXFTP服务.md
Normal file
@@ -0,0 +1,111 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker-Compose部署Simplex服务器SMPXFTP服务
|
||||
|
||||
[官网](https://simplex.chat/) [Github安装文档](https://github.com/simplex-chat/simplex-chat/blob/stable/docs/SERVER.md) [客户端下载](https://simplex.chat/downloads/)
|
||||
|
||||
| 服务器服务 | IP |
|
||||
| :-------------------------------------: | :----------: |
|
||||
| simplex-smp-server、simplex-xftp-server | 192.168.1.10 |
|
||||
|
||||
## 部署SMP/XFTP服务
|
||||
|
||||
1. 创建持久化目录
|
||||
|
||||
```bash
|
||||
mkdir -p /data/simplex/{xftp,smp}/{config,logs} && mkdir -p /data/simplex/xftp/files
|
||||
```
|
||||
|
||||
2. 创建 Docker-Compose Env 文件
|
||||
|
||||
```bash
|
||||
cat << EOF >> .env
|
||||
SIMPLEX_ADDR=192.168.1.10
|
||||
XFTP_ADDR=192.168.1.10
|
||||
EOF
|
||||
```
|
||||
|
||||
3. 创建 Docker-Compose 文件
|
||||
|
||||
```bash
|
||||
vi docker-compose.yaml
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
version: '3'
|
||||
|
||||
networks:
|
||||
simplex:
|
||||
|
||||
services:
|
||||
simplex-smp-server:
|
||||
image: simplexchat/smp-server:latest
|
||||
container_name: simplex-smp-server
|
||||
restart: always
|
||||
ports:
|
||||
- "5223:5223"
|
||||
volumes:
|
||||
- /data/simplex/smp/config:/etc/opt/simplex:Z
|
||||
- /data/simplex/smp/logs:/var/opt/simplex:Z
|
||||
environment:
|
||||
- ADDR=${SIMPLEX_ADDR}
|
||||
# - PASS=""
|
||||
networks:
|
||||
- simplex
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
|
||||
simplex-xftp-server:
|
||||
image: simplexchat/xftp-server:latest
|
||||
container_name: simplex-xftp-server
|
||||
ports:
|
||||
- "443:443"
|
||||
restart: always
|
||||
volumes:
|
||||
- /data/simplex/xftp/config:/etc/opt/simplex-xftp:Z
|
||||
- /data/simplex/xftp/logs:/var/opt/simplex-xftp:Z
|
||||
- /data/simplex/xftp/files:/srv/xftp:X
|
||||
environment:
|
||||
- ADDR=${XFTP_ADDR}
|
||||
- QUOTA=50gb
|
||||
networks:
|
||||
- simplex
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
```
|
||||
|
||||
4. 启动
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
5. 查看日志获取链接信息
|
||||
|
||||
```bash
|
||||
docker logs -f simplex-smp-server
|
||||
```
|
||||
|
||||
```bash
|
||||
docker logs -f simplex-xftp-server
|
||||
```
|
||||
|
||||
> 保存以 `smp://` 和 `xftp://` 开头的链接信息
|
||||
|
||||
6. 到客户端点击头像、网络和服务器、SMP服务器/XFTP服务器、添加服务器、填写链接信息并保存
|
||||
|
||||
> 链接信息格式为:
|
||||
>
|
||||
> ```bash
|
||||
> smp://密钥=@访问地址
|
||||
> ```
|
||||
|
||||
**问题记录**
|
||||
|
||||
`simplex-xftp-server` 端口号为 443 会导致有些人的端口冲突,所以我们可以修改 Docker-Compose 文件内的对外端口比如 "5233:443",启动后我们客户端链接时需要在IP或域名后添加端口号。如:smp://密钥=@访问地址:5233
|
44
Docker/Compose/Docs/Docker-Compose部署Watchtower.md
Normal file
44
Docker/Compose/Docs/Docker-Compose部署Watchtower.md
Normal file
@@ -0,0 +1,44 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker-Compose部署Watchtower
|
||||
|
||||
[Github仓库](https://github.com/containrrr/watchtower)
|
||||
|
||||
## 介绍
|
||||
|
||||
Watchtower 是一个开源的容器监控和自动更新工具,设计用于Docker容器环境。它可以监控正在运行的容器及其使用的镜像,当发现镜像有更新时,自动拉取新镜像并重新启动容器。这种自动化管理方式有助于确保部署的应用保持最新状态,从而减少安全风险和改进功能。
|
||||
|
||||
## 部署
|
||||
|
||||
1. 创建 Docker-Compose 文件
|
||||
|
||||
```bash
|
||||
vi docker-compose.yaml
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
services:
|
||||
watchtower:
|
||||
image: containrrr/watchtower:latest
|
||||
container_name: watchtower
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
command: --interval 14400
|
||||
```
|
||||
|
||||
**Command参数解释**
|
||||
|
||||
- `--interval 14400`:设置 `watchtower` 检查更新的时间间隔为 14400 秒(即 4 小时)。`watchtower` 将每 4 小时检查一次所有运行的容器是否有可用的镜像更新,并在发现新版本时自动重新部署容器。
|
||||
|
||||
- 其他参数请看此文档
|
||||
|
||||
[Docker部署Watchtower管理容器更新](https://gitee.com/offends/Kubernetes/tree/main/Docker/Docs/Docker%E9%83%A8%E7%BD%B2Watchtower%E7%AE%A1%E7%90%86%E5%AE%B9%E5%99%A8%E6%9B%B4%E6%96%B0.md)
|
||||
|
||||
2. 启动
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
68
Docker/Compose/Docs/Docker-compose安装.md
Normal file
68
Docker/Compose/Docs/Docker-compose安装.md
Normal file
@@ -0,0 +1,68 @@
|
||||
> 作者:丁辉
|
||||
|
||||
# Docker-compose安装
|
||||
|
||||
## 网络安装
|
||||
|
||||
> 缺点: 网络安装版本一般过低,大概率为v1
|
||||
|
||||
- Centos
|
||||
|
||||
```bash
|
||||
yum -y install docker-compose
|
||||
```
|
||||
|
||||
- Ubuntu
|
||||
|
||||
```bash
|
||||
apt -y install docker-compose
|
||||
```
|
||||
|
||||
## 二进制安装
|
||||
|
||||
[Github下载](https://github.com/docker/compose/releases)
|
||||
|
||||
1. 下载
|
||||
|
||||
```
|
||||
curl -L "https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
2. 配置权限
|
||||
|
||||
```bash
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
3. 配置软连接
|
||||
|
||||
```bash
|
||||
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
|
||||
```
|
||||
|
||||
4. 查看结果
|
||||
|
||||
```bash
|
||||
docker-compose --version
|
||||
```
|
||||
|
||||
## PIP安装
|
||||
|
||||
- 安装
|
||||
|
||||
```bash
|
||||
pip install -U docker-compose
|
||||
```
|
||||
|
||||
- 卸载
|
||||
|
||||
```bash
|
||||
pip uninstall docker-compose
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
466
Docker/Compose/Docs/Docker-compse部署Harbor.md
Normal file
466
Docker/Compose/Docs/Docker-compse部署Harbor.md
Normal file
@@ -0,0 +1,466 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker-compse部署Harbor
|
||||
|
||||
[官网](https://goharbor.io/) [包下载位置](https://github.com/goharbor/harbor/releases)
|
||||
|
||||
> 离线版本:harbor-offline-installer-v*.tgz
|
||||
>
|
||||
> 在线版本:harbor-online-installer-v*.tgz
|
||||
|
||||
## 安装Docker-Compose
|
||||
|
||||
- Centos
|
||||
|
||||
```bash
|
||||
yum install docker-compose -y
|
||||
```
|
||||
|
||||
- Ubuntu
|
||||
|
||||
```bash
|
||||
apt install docker-compose -y
|
||||
```
|
||||
|
||||
## 开始安装
|
||||
|
||||
1. 下载软件包
|
||||
|
||||
> 本文以现最新版本 v2.8.3 举例
|
||||
|
||||
```bash
|
||||
wget https://ghproxy.com/https://github.com/goharbor/harbor/releases/download/v2.8.3/harbor-offline-installer-v2.8.3.tgz
|
||||
```
|
||||
|
||||
2. 解压文件
|
||||
|
||||
```bash
|
||||
tar -zxvf harbor-offline-installer-v*.tgz && cd harbor && cp harbor.yml.tmpl harbor.yml
|
||||
```
|
||||
|
||||
3. 更改 harbor.yml 文件
|
||||
|
||||
> 配置 Tcp IP 访问
|
||||
|
||||
```bash
|
||||
vi harbor.yml
|
||||
```
|
||||
|
||||
更改如下内容
|
||||
|
||||
```yml
|
||||
hostname: harbor.store.com
|
||||
http:
|
||||
port: 9000
|
||||
|
||||
#注释域名证书访问
|
||||
#https:
|
||||
#port: 443
|
||||
#certificate: /your/certificate/path
|
||||
#private_key: /your/private/key/path
|
||||
|
||||
harbor_admin_password: Harbor12345
|
||||
|
||||
data_volume: /data
|
||||
```
|
||||
|
||||
4. 初始化配置
|
||||
|
||||
```bash
|
||||
./prepare
|
||||
```
|
||||
|
||||
5. 启动 harbor
|
||||
|
||||
```bash
|
||||
./install.sh
|
||||
```
|
||||
|
||||
6. 安装完成后更新 Docker 配置允许使用私有仓库
|
||||
|
||||
修改 Docker 配置文件
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
添加如下内容
|
||||
|
||||
```json
|
||||
{
|
||||
"insecure-registries": ["1.1.1.1:9000"]
|
||||
}
|
||||
```
|
||||
|
||||
7. 重载 Docker
|
||||
|
||||
```bash
|
||||
systemctl reload docker
|
||||
```
|
||||
|
||||
8. 登录测试
|
||||
|
||||
```bash
|
||||
docker login 1.1.1.1:9000 -uadmin -pHarbor12345
|
||||
```
|
||||
|
||||
## 配置外部数据库
|
||||
|
||||
更改 harbor.yml 文件, 更改如下内容
|
||||
|
||||
```yml
|
||||
external_database:
|
||||
harbor:
|
||||
host: harbor_db_host
|
||||
port: harbor_db_port
|
||||
db_name: harbor_db_name
|
||||
username: harbor_db_username
|
||||
password: harbor_db_password
|
||||
ssl_mode: disable
|
||||
max_idle_conns: 2
|
||||
max_open_conns: 0
|
||||
notary_signer:
|
||||
host: notary_signer_db_host
|
||||
port: notary_signer_db_port
|
||||
db_name: notary_signer_db_name
|
||||
username: notary_signer_db_username
|
||||
password: notary_signer_db_password
|
||||
ssl_mode: disable
|
||||
notary_server:
|
||||
host: notary_server_db_host
|
||||
port: notary_server_db_port
|
||||
db_name: notary_server_db_name
|
||||
username: notary_server_db_username
|
||||
password: notary_server_db_password
|
||||
ssl_mode: disable
|
||||
|
||||
external_redis:
|
||||
host: redis:6379
|
||||
password:
|
||||
registry_db_index: 1
|
||||
jobservice_db_index: 2
|
||||
trivy_db_index: 5
|
||||
idle_timeout_seconds: 30
|
||||
```
|
||||
|
||||
## 使用 trivy 镜像漏洞检测
|
||||
|
||||
1. 更改 harbor.yml 文件, 更改如下内容
|
||||
|
||||
```bash
|
||||
trivy:
|
||||
ignore_unfixed: false
|
||||
skip_update: true #跳过更新
|
||||
offline_scan: true #离线扫描
|
||||
security_check: vuln
|
||||
insecure: false
|
||||
```
|
||||
|
||||
2. 启动 harbor 是添加 trivy 启动参数
|
||||
|
||||
```bash
|
||||
./install.sh --with-trivy
|
||||
```
|
||||
|
||||
## 离线环境使用 trivy 导入漏洞数据库
|
||||
|
||||
创建持久化目录(如果 harbor 已启动, 则停止后替换目录内容)
|
||||
|
||||
```bash
|
||||
mkdir -p /data/trivy-adapter/trivy/db/
|
||||
```
|
||||
|
||||
### 方法一
|
||||
|
||||
[oras官网下载地址](https://github.com/oras-project/oras/releases)
|
||||
|
||||
1. 下载软件
|
||||
|
||||
```bash
|
||||
wget https://ghproxy.com/https://github.com/oras-project/oras/releases/download/v1.0.1/oras_1.0.1_linux_amd64.tar.gz
|
||||
```
|
||||
|
||||
2. 解压文件
|
||||
|
||||
```bash
|
||||
tar -zxvf oras_*_linux_amd64.tar.gz && mv oras-install/oras /usr/local/bin/
|
||||
```
|
||||
|
||||
3. 下载数据
|
||||
|
||||
```bash
|
||||
oras pull ghcr.io/aquasecurity/trivy-db:2
|
||||
```
|
||||
|
||||
4. 将数据解压到指定目录
|
||||
|
||||
```bash
|
||||
tar -xzvf db.tar.gz -C /data/trivy-adapter/trivy/db/
|
||||
```
|
||||
|
||||
### 方法二
|
||||
|
||||
> 外网搭建 harbor, 上传 Nginx 和 Tomcat 进行检测, 获取数据目录 java-db 和 db
|
||||
|
||||
1. 线上环境打包书库目录
|
||||
|
||||
```bash
|
||||
cd /data/trivy-adapter/
|
||||
tar -zcvf trivy-db-offline.tar.gz trivy
|
||||
```
|
||||
|
||||
2. 在离线环境将数据解压到指定目录
|
||||
|
||||
```bash
|
||||
tar -xzvf trivy-db-offline.tar.gz -C /data/trivy-adapter/trivy/db/
|
||||
```
|
||||
|
||||
3. 授权目录
|
||||
|
||||
```bash
|
||||
chown -R 10000:10000 /data/trivy-adapter/trivy/db/
|
||||
```
|
||||
|
||||
4. 重新启动 harbor 后完成
|
||||
|
||||
## Harbor配置签发Https配置私有证书
|
||||
|
||||
### 方法一(cfssl)
|
||||
|
||||
1. 首先修改 harbor.yml 文件, 配置证书
|
||||
|
||||
```yml
|
||||
hostname: harbor.store.com
|
||||
http:
|
||||
port: 80
|
||||
|
||||
https:
|
||||
port: 443
|
||||
certificate: /data/ssl/harbor/harbor.pem
|
||||
private_key: /data/ssl/harbor/harbor-key.pem
|
||||
|
||||
harbor_admin_password: Harbor12345
|
||||
|
||||
data_volume: /data
|
||||
```
|
||||
|
||||
2. 下载配置证书工具
|
||||
|
||||
[cfssl下载地址](https://github.com/cloudflare/cfssl/releases/)
|
||||
|
||||
```bash
|
||||
wget https://ghproxy.com/https://github.com/cloudflare/cfssl/releases/download/v1.6.3/cfssl_1.6.3_linux_amd64 \ -O /usr/local/bin/cfssl
|
||||
|
||||
wget https://ghproxy.com/https://github.com/cloudflare/cfssl/releases/download/v1.6.3/cfssljson_1.6.3_linux_amd64 \ -O /usr/local/bin/cfssljson
|
||||
|
||||
wget https://ghproxy.com/https://github.com/cloudflare/cfssl/releases/download/v1.6.3/cfssl-certinfo_1.6.3_linux_amd64 \ -O /usr/local/bin/cfssl-certinfo
|
||||
|
||||
chmod +x /usr/local/bin/cfssl*
|
||||
```
|
||||
|
||||
3. 生成并CA配置文件
|
||||
|
||||
```json
|
||||
#cfssl print-defaults config > ca-config.json
|
||||
cat > ca-config.json <<EOF
|
||||
{
|
||||
"signing": {
|
||||
"default": {
|
||||
"expiry": "87600h"
|
||||
},
|
||||
"profiles": {
|
||||
"harbor": {
|
||||
"expiry": "87600h",
|
||||
"usages": [
|
||||
"signing",
|
||||
"key encipherment",
|
||||
"server auth",
|
||||
"client auth"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
> `default.expiry`:默认证书有效期(单位:h)
|
||||
> `profiles.harbor`:为服务使用该配置文件颁发证书的配置模块
|
||||
> signing:签署,表示该证书可用于签名其它证书;生成的 ca.pem 证书中 CA=TRUE
|
||||
> `key encipherment`:密钥加密
|
||||
> `profiles`:指定了不同角色的配置信息;可以定义多个 profiles,分别指定不同的过期时间、使用场景等参数;后续在签名证书时使用某个 profile
|
||||
> `server auth`:服务器身份验证;表示 client 可以用该 CA 对 server 提供的证书进行验证
|
||||
> `client auth`:客户端身份验证;表示 server 可以用该 CA 对 client 提供的证书进行验证
|
||||
|
||||
4. 生成并修改默认csr请求文件
|
||||
|
||||
```json
|
||||
#cfssl print-defaults csr > ca-csr.json
|
||||
cat > ca-csr.json <<EOF
|
||||
{
|
||||
"CN": "harbor",
|
||||
"hosts": [
|
||||
],
|
||||
"key": {
|
||||
"algo": "rsa",
|
||||
"size": 2048
|
||||
},
|
||||
"names": [
|
||||
{
|
||||
"C": "CN",
|
||||
"ST": "Beijing",
|
||||
"L": "Beijing"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
> `hosts`:包含的授权范围,不在此范围的的节点或者服务使用此证书就会报证书不匹配错误,证书如果不包含可能会出现无法连接的情况(此处是CA机构的可为空)
|
||||
> `Key`: 指定使用的加密算法,一般使用rsa非对称加密算法(algo:rsa;size:2048)
|
||||
> `CN`:Common Name,kube-apiserver 从证书中提取该字段作为请求的用户名 (User Name);浏览器使用该字段验证网站是否合法
|
||||
> `CN`是域名,也就是你现在使用什么域名就写什么域名
|
||||
> `O`:Organization,从证书中提取该字段作为请求用户所属的组 (Group)
|
||||
|
||||
5. 初始化CA
|
||||
|
||||
```bash
|
||||
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
|
||||
```
|
||||
|
||||
> 可以看到,当前目录下新生成了`ca.csr`、`ca-key.pem`、`ca.pem`这3个文件。 ca-key.pem、ca.pem这两个是CA相关的证书,通过这个CA来签署服务端证书。
|
||||
|
||||
6. 创建并修改Harbor证书请求文件
|
||||
|
||||
```bash
|
||||
#cfssl print-defaults csr > harbor-csr.json
|
||||
cat > harbor-csr.json <<EOF
|
||||
{
|
||||
"CN": "1.1.1.1",
|
||||
"hosts": [
|
||||
"127.0.0.1",
|
||||
"1.1.1.1"
|
||||
],
|
||||
"key": {
|
||||
"algo": "rsa",
|
||||
"size": 2048
|
||||
},
|
||||
"names": [
|
||||
{
|
||||
"C": "CN",
|
||||
"ST": "Beijing",
|
||||
"L": "Beijing"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
7. 使用请求文件根据CA配置颁发证书
|
||||
|
||||
```bash
|
||||
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem \
|
||||
-config=ca-config.json \
|
||||
-profile=harbor harbor-csr.json | cfssljson -bare harbor
|
||||
```
|
||||
|
||||
8. 拷贝证书到指定目录下
|
||||
|
||||
```bash
|
||||
cp harbor.pem harbor-key.pem /data/ssl/harbor/
|
||||
```
|
||||
|
||||
> `-config`:指定CA证书机构的配置文件
|
||||
> `-profile`:指定使用CA配置文件中的哪个模块(此处harbor对应配置文件中的harbor)
|
||||
> `harbor.pem`:harbor服务的数字证书
|
||||
> `harbor-key`.pem:harbor服务的私钥
|
||||
|
||||
### 方法二(openssl)
|
||||
|
||||
1. 首先修改 harbor.yml 文件, 配置证书
|
||||
|
||||
```yml
|
||||
hostname: harbor.store.com
|
||||
http:
|
||||
port: 80
|
||||
|
||||
https:
|
||||
port: 443
|
||||
certificate: /data/ssl/harbor/harbor.crt
|
||||
private_key: /data/ssl/harbor/harbor-key.key
|
||||
|
||||
harbor_admin_password: Harbor12345
|
||||
|
||||
data_volume: /data
|
||||
```
|
||||
|
||||
2. 创建 ca.key
|
||||
|
||||
```bash
|
||||
openssl genrsa -out ca.key 4096
|
||||
```
|
||||
|
||||
3. 创建 ca.crt
|
||||
|
||||
```bash
|
||||
openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.com" -key ca.key -out ca.crt
|
||||
```
|
||||
|
||||
4. 创建 harbor.key
|
||||
|
||||
```bash
|
||||
openssl genrsa -out harbor.key 4096
|
||||
```
|
||||
|
||||
5. 创建 harbor.csr
|
||||
|
||||
```bash
|
||||
openssl req -sha512 -new -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.com" -key harbor.key -out harbor.csr
|
||||
```
|
||||
|
||||
6. 创建x509 v3 扩展 文件
|
||||
|
||||
```bash
|
||||
cat > v3.ext <<EOF
|
||||
authorityKeyIdentifier=keyid,issuer
|
||||
basicConstraints=CA:FALSE
|
||||
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @alt_names
|
||||
|
||||
[alt_names]
|
||||
DNS.1=harbor.com
|
||||
EOF
|
||||
```
|
||||
|
||||
7. 使用 v3.ext 文件为 harbor 服务器创建证书
|
||||
|
||||
```bash
|
||||
openssl x509 -req -sha512 -days 3650 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in harbor.csr -out harbor.crt
|
||||
```
|
||||
|
||||
### Docker配置证书验证
|
||||
|
||||
1. 创建目录
|
||||
|
||||
```bash
|
||||
mkdir -p /etc/docker/certs.d/harbor.com
|
||||
```
|
||||
|
||||
2. 将 crt 文件转换为 cert 文件
|
||||
|
||||
```bash
|
||||
openssl x509 -inform PEM -in harbor.crt -out harbor.cert
|
||||
```
|
||||
|
||||
3. 将 cert 和 key 放在对应目录下
|
||||
|
||||
```bash
|
||||
cp harbor.cert harbor.key ca.crt /etc/docker/certs.d/harbor.com/
|
||||
```
|
||||
|
||||
4. 重启docker
|
||||
|
||||
```bash
|
||||
systemctl restart docker
|
||||
```
|
25
Docker/Compose/Docs/更新Docker-compose部署的应用.md
Normal file
25
Docker/Compose/Docs/更新Docker-compose部署的应用.md
Normal file
@@ -0,0 +1,25 @@
|
||||
> 作者:丁辉
|
||||
|
||||
# 更新Docker-compose部署的应用
|
||||
|
||||
> 进入到你 docker-compose 所在的文件夹下,执行
|
||||
|
||||
1. 拉取最新镜像
|
||||
|
||||
```bash
|
||||
docker-compose pull
|
||||
```
|
||||
|
||||
2. 使用新镜像重启容器
|
||||
|
||||
```bash
|
||||
docker-compose up -d --remove-orphans
|
||||
```
|
||||
|
||||
3. 清理旧容器残留镜像
|
||||
|
||||
```bash
|
||||
docker image prune
|
||||
```
|
||||
|
||||
|
92
Docker/Compose/README.md
Normal file
92
Docker/Compose/README.md
Normal file
@@ -0,0 +1,92 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker-compose使用示例
|
||||
|
||||
**前提:**
|
||||
|
||||
1. 克隆代码
|
||||
|
||||
```bash
|
||||
git clone https://gitee.com/offends/Kubernetes.git
|
||||
cd Kubernetes/Docker/Compose
|
||||
```
|
||||
|
||||
2. 进入示例目录
|
||||
|
||||
```bash
|
||||
cd /Yml
|
||||
```
|
||||
|
||||
## 构建镜像
|
||||
|
||||
```bash
|
||||
docker-compose -f build-compose.yml build
|
||||
```
|
||||
|
||||
**参数解释**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| ------------ | --------------------------------------------------------- |
|
||||
| `build` | 定义服务的构建方式 |
|
||||
| `context` | 构建上下文的路径,`.` 表示使用当前目录 |
|
||||
| `dockerfile` | 指定用于构建镜像的 Dockerfile 文件的路径 |
|
||||
| `args` | 定义构建参数的键值对,这里的 `buildno: 1` 是一个构建参数 |
|
||||
| `labels` | 为构建的镜像添加标签,这里添加了一个名为 "offends" 的标签 |
|
||||
| `target` | 指定构建阶段的目标,这里设置为 `prod` |
|
||||
|
||||
## 安装 Gitlab
|
||||
|
||||
- 指定文件名启动
|
||||
|
||||
```bash
|
||||
docker-compose -f gitlab-compose.yml up -d
|
||||
```
|
||||
|
||||
- 停止
|
||||
|
||||
```bash
|
||||
docker-compose -f gitlab-compose.yml down
|
||||
```
|
||||
|
||||
## 示例模版演示
|
||||
|
||||
- ```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
**YML参数解释**
|
||||
|
||||
[Docker从入门到实践](https://yeasy.gitbook.io/docker_practice/compose/compose_file) [菜鸟教学](https://www.runoob.com/docker/docker-compose.html)
|
||||
|
||||
**Docker-compose命令参数解释**
|
||||
|
||||
| 命令 | 描述 |
|
||||
| ------- | ------------------------------------------------- |
|
||||
| build | 构建或重建服务 |
|
||||
| config | 解析、解决并渲染规范格式的Compose文件 |
|
||||
| cp | 在服务容器和本地文件系统之间复制文件/文件夹 |
|
||||
| create | 为一个服务创建容器 |
|
||||
| down | 停止并移除容器和网络 |
|
||||
| events | 接收来自容器的实时事件 |
|
||||
| exec | 在运行中的容器中执行命令 |
|
||||
| images | 列出由创建的容器使用的镜像 |
|
||||
| kill | 强制停止服务容器 |
|
||||
| logs | 查看容器输出 |
|
||||
| ls | 列出运行中的Compose项目 |
|
||||
| pause | 暂停服务 |
|
||||
| port | 打印端口绑定的公共端口 |
|
||||
| ps | 列出容器 |
|
||||
| pull | 拉取服务镜像 |
|
||||
| push | 推送服务镜像 |
|
||||
| restart | 重启服务容器 |
|
||||
| rm | 删除已停止的服务容器 |
|
||||
| run | 在一个服务上运行一次性命令 |
|
||||
| scale | 缩放服务 |
|
||||
| start | 启动服务 |
|
||||
| stop | 停止服务 |
|
||||
| top | 显示运行中的进程 |
|
||||
| unpause | 恢复暂停的服务 |
|
||||
| up | 创建并启动容器 |
|
||||
| version | 显示 Docker Compose 版本信息 |
|
||||
| wait | 阻塞直到第一个服务容器停止 |
|
||||
| watch | 监视服务的构建环境,当文件更新时重新构建/刷新容器 |
|
5
Docker/Compose/Yml/Dockerfile
Normal file
5
Docker/Compose/Yml/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM busybox:latest AS prod
|
||||
|
||||
RUN echo "启动成功" > /file.txt
|
||||
|
||||
CMD ["tail","-f","/file.txt"]
|
16
Docker/Compose/Yml/build-compose.yml
Normal file
16
Docker/Compose/Yml/build-compose.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
webapp:
|
||||
build: ./
|
||||
|
||||
# services:
|
||||
# webapp:
|
||||
# build:
|
||||
# context: ./
|
||||
# dockerfile: Dockerfile
|
||||
# args:
|
||||
# buildno: 1
|
||||
# labels:
|
||||
# - "offends"
|
||||
# target: prod
|
7
Docker/Compose/Yml/docker-compose.yml
Normal file
7
Docker/Compose/Yml/docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
ports:
|
||||
- "80:80"
|
52
Docker/Compose/Yml/gitlab-compose.yml
Normal file
52
Docker/Compose/Yml/gitlab-compose.yml
Normal file
@@ -0,0 +1,52 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
gitlab:
|
||||
depends_on:
|
||||
- redis
|
||||
- postgresql
|
||||
restart: always
|
||||
image: sameersbn/gitlab:latest
|
||||
environment:
|
||||
- DEBUG=false
|
||||
- TZ=Asia/Shanghai
|
||||
- GITLAB_TIMEZONE=Beijing
|
||||
- REDIS_HOST=redis
|
||||
- REDIS_PORT=6379
|
||||
- DB_ADAPTER=postgresql
|
||||
- DB_HOST=postgresql
|
||||
- DB_PORT=5432
|
||||
- DB_USER=gitlab
|
||||
- DB_PASS=gitlab
|
||||
- DB_NAME=gitlabhq_production
|
||||
- GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string
|
||||
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
|
||||
- GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
|
||||
- GITLAB_HOST=192.168.1.10
|
||||
- GITLAB_PORT=80
|
||||
- GITLAB_SSH_HOST=192.168.1.10
|
||||
- GITLAB_SSH_PORT=222
|
||||
ports:
|
||||
- "222:22"
|
||||
- "80:80"
|
||||
volumes:
|
||||
- /data/gitlab/data:/home/git/data:Z
|
||||
- /data/gitlab/node_modules:/home/git/gitlab/node_modules:Z
|
||||
- /data/gitlab/log:/var/log/gitlab:Z
|
||||
|
||||
redis:
|
||||
restart: always
|
||||
image: sameersbn/redis:latest
|
||||
volumes:
|
||||
- /data/gitlab/redis:/var/lib/redis:Z
|
||||
|
||||
postgresql:
|
||||
restart: always
|
||||
image: sameersbn/postgresql:14
|
||||
environment:
|
||||
- DB_EXTENSION=pg_trgm,btree_gist
|
||||
- DB_USER=gitlab
|
||||
- DB_PASS=gitlab
|
||||
- DB_NAME=gitlabhq_production
|
||||
volumes:
|
||||
- /data/gitlab/postgresql:/var/lib/postgresql:Z
|
33
Docker/Compose/install.sh
Normal file
33
Docker/Compose/install.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 安装 Docker Compose
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2023-12-27
|
||||
#############################################################################################
|
||||
|
||||
# 加载检测脚本
|
||||
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
||||
|
||||
# 定义变量
|
||||
VERSION="v2.23.3"
|
||||
|
||||
# 安装 Docker Compose
|
||||
# 检测某个systemd服务是否存在
|
||||
function CHECK_SYSTEMD(){
|
||||
if ! command -v docker-compose >/dev/null 2>&1; then
|
||||
INSTALL_DOCKER_COMPOSE
|
||||
else
|
||||
SEND_INFO "Docker-compose 服务已安装,版本为: $(docker-compose --version | grep -oP 'v\d+\.\d+\.\d+')"
|
||||
fi
|
||||
}
|
||||
|
||||
function INSTALL_DOCKER_COMPOSE(){
|
||||
SEND_INFO "开始安装 Docker Compose"
|
||||
curl -L "https://github.com/docker/compose/releases/download/$VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
NULL_TRUE chmod +x /usr/local/bin/docker-compose
|
||||
NULL_TRUE ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
|
||||
SEND_INFO "Docker Compose 安装完成,版本为: $(docker-compose --version | grep -oP 'v\d+\.\d+\.\d+')"
|
||||
}
|
||||
|
||||
CHECK_SYSTEMD
|
15
Docker/Dockerfile/Aliyun-dns-sync/Dockerfile
Normal file
15
Docker/Dockerfile/Aliyun-dns-sync/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM python:3
|
||||
|
||||
RUN pip install aliyun-python-sdk-core -i https://pypi.tuna.tsinghua.edu.cn/simple \
|
||||
&& sleep 2 \
|
||||
&& pip install aliyun-python-sdk-alidns -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
RUN touch /var/log/python.log \
|
||||
&& sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list.d/debian.sources \
|
||||
&& apt-get update \
|
||||
&& apt-get -y install cron \
|
||||
&& echo '*/1 * * * * sh /aliyun-dns-sync/cron.sh' | crontab
|
||||
|
||||
COPY ./File/* /aliyun-dns-sync/
|
||||
|
||||
CMD [ "bash", "/aliyun-dns-sync/start.sh" ]
|
141
Docker/Dockerfile/Aliyun-dns-sync/File/aliyun-dns-sync.py
Normal file
141
Docker/Dockerfile/Aliyun-dns-sync/File/aliyun-dns-sync.py
Normal file
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python
|
||||
#coding=utf-8
|
||||
|
||||
# 加载核心SDK
|
||||
#from aliyunsdkcore import client
|
||||
#from aliyunsdksts.request.v20150401 import AssumeRoleRequest
|
||||
#import json
|
||||
#import oss2
|
||||
|
||||
from aliyunsdkcore.client import AcsClient
|
||||
from aliyunsdkcore.acs_exception.exceptions import ClientException
|
||||
from aliyunsdkcore.acs_exception.exceptions import ServerException
|
||||
|
||||
# 加载获取 、 新增、 更新、 删除接口
|
||||
from aliyunsdkalidns.request.v20150109 import DescribeSubDomainRecordsRequest, AddDomainRecordRequest, UpdateDomainRecordRequest, DeleteDomainRecordRequest
|
||||
|
||||
# 加载内置模块
|
||||
import json,urllib
|
||||
|
||||
# AccessKey 和 Secret 建议使用 RAM 子账户的 KEY 和 SECRET 增加安全性
|
||||
ID = ''
|
||||
SECRET = ''
|
||||
|
||||
# 地区节点 可选地区取决于你的阿里云帐号等级,普通用户只有四个,分别是杭州、上海、深圳、河北,具体参考官网API
|
||||
regionId = 'cn-hangzhou'
|
||||
|
||||
# 配置认证信息
|
||||
client = AcsClient(ID, SECRET, regionId)
|
||||
|
||||
# 设置主域名
|
||||
DomainName = ''
|
||||
|
||||
# 子域名列表 列表参数可根据实际需求增加或减少值
|
||||
SubDomainList = ['@','www']
|
||||
|
||||
# 获取外网IP 三个地址返回的ip地址格式各不相同,3322 的是最纯净的格式, 备选1为 json格式 备选2 为curl方式获取 两个备选地址都需要对获取值作进一步处理才能使用
|
||||
def getIp():
|
||||
# 备选地址: 1. http://pv.sohu.com/cityjson?ie=utf-8 2. curl -L tool.lu/ip
|
||||
with urllib.request.urlopen('http://www.3322.org/dyndns/getip') as response:
|
||||
html = response.read()
|
||||
ip = str(html, encoding='utf-8').replace("\n", "")
|
||||
return ip
|
||||
|
||||
# 查询记录
|
||||
def getDomainInfo(SubDomain):
|
||||
request = DescribeSubDomainRecordsRequest.DescribeSubDomainRecordsRequest()
|
||||
request.set_accept_format('json')
|
||||
|
||||
# 设置要查询的记录类型为 A记录 官网支持A / CNAME / MX / AAAA / TXT / NS / SRV / CAA / URL隐性(显性)转发 如果有需要可将该值配置为参数传入
|
||||
request.set_Type("A")
|
||||
#request.set_Type("www")
|
||||
# 指定查记的域名 格式为 'test.binghe.com'
|
||||
request.set_SubDomain(SubDomain)
|
||||
|
||||
response = client.do_action_with_exception(request)
|
||||
response = str(response, encoding='utf-8')
|
||||
|
||||
# 将获取到的记录转换成json对象并返回
|
||||
return json.loads(response)
|
||||
|
||||
# 新增记录 (默认都设置为A记录,通过配置set_Type可设置为其他记录)
|
||||
def addDomainRecord(client,value,rr,domainname):
|
||||
request = AddDomainRecordRequest.AddDomainRecordRequest()
|
||||
request.set_accept_format('json')
|
||||
|
||||
# request.set_Priority('1') # MX 记录时的必选参数
|
||||
request.set_TTL('600') # 可选值的范围取决于你的阿里云账户等级,免费版为 600 - 86400 单位为秒
|
||||
request.set_Value(value) # 新增的 ip 地址
|
||||
request.set_Type('A') # 记录类型
|
||||
request.set_RR(rr) # 子域名名称
|
||||
request.set_DomainName(domainname) #主域名
|
||||
|
||||
# 获取记录信息,返回信息中包含 TotalCount 字段,表示获取到的记录条数 0 表示没有记录, 其他数字为多少表示有多少条相同记录,正常有记录的值应该为1,如果值大于1则应该检查是不是重复添加了相同的记录
|
||||
response = client.do_action_with_exception(request)
|
||||
response = str(response, encoding='utf-8')
|
||||
relsult = json.loads(response)
|
||||
return relsult
|
||||
|
||||
# 更新记录
|
||||
def updateDomainRecord(client,value,rr,record_id):
|
||||
request = UpdateDomainRecordRequest.UpdateDomainRecordRequest()
|
||||
request.set_accept_format('json')
|
||||
|
||||
# request.set_Priority('1')
|
||||
request.set_TTL('600')
|
||||
request.set_Value(value) # 新的ip地址
|
||||
request.set_Type('A')
|
||||
request.set_RR(rr)
|
||||
request.set_RecordId(record_id) # 更新记录需要指定 record_id ,该字段为记录的唯一标识,可以在获取方法的返回信息中得到该字段的值
|
||||
|
||||
response = client.do_action_with_exception(request)
|
||||
response = str(response, encoding='utf-8')
|
||||
return response
|
||||
|
||||
# 删除记录
|
||||
def delDomainRecord(client,subdomain):
|
||||
info = getDomainInfo(subdomain)
|
||||
if info['TotalCount'] == 0:
|
||||
print('没有相关的记录信息,删除失败!')
|
||||
elif info["TotalCount"] == 1:
|
||||
print('准备删除记录')
|
||||
request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
|
||||
request.set_accept_format('json')
|
||||
|
||||
record_id = info["DomainRecords"]["Record"][0]["RecordId"]
|
||||
request.set_RecordId(record_id) # 删除记录需要指定 record_id ,该字段为记录的唯一标识,可以在获取方法的返回信息中得到该字段的值
|
||||
result = client.do_action_with_exception(request)
|
||||
print('删除成功,返回信息:')
|
||||
print(result)
|
||||
else:
|
||||
# 正常不应该有多条相同的记录,如果存在这种情况,应该手动去网站检查核实是否有操作失误
|
||||
print("存在多个相同子域名解析记录值,请核查后再操作!")
|
||||
|
||||
# 有记录则更新,没有记录则新增
|
||||
def setDomainRecord(client,value,rr,domainname):
|
||||
info = getDomainInfo(rr + '.' + domainname)
|
||||
if info['TotalCount'] == 0:
|
||||
print('准备添加新记录')
|
||||
add_result = addDomainRecord(client,value,rr,domainname)
|
||||
print(add_result)
|
||||
elif info["TotalCount"] == 1:
|
||||
print('准备更新已有记录')
|
||||
record_id = info["DomainRecords"]["Record"][0]["RecordId"]
|
||||
cur_ip = getIp()
|
||||
old_ip = info["DomainRecords"]["Record"][0]["Value"]
|
||||
if cur_ip == old_ip:
|
||||
print ("新ip与原ip相同,不更新!")
|
||||
else:
|
||||
update_result = updateDomainRecord(client,value,rr,record_id)
|
||||
print('更新成功,返回信息:')
|
||||
print(update_result)
|
||||
else:
|
||||
# 正常不应该有多条相同的记录,如果存在这种情况,应该手动去网站检查核实是否有操作失误
|
||||
print("存在多个相同子域名解析记录值,请核查删除后再操作!")
|
||||
|
||||
|
||||
IP = getIp()
|
||||
|
||||
# 循环子域名列表进行批量操作
|
||||
for x in SubDomainList:
|
||||
setDomainRecord(client,IP,x,DomainName)
|
4
Docker/Dockerfile/Aliyun-dns-sync/File/cron.sh
Normal file
4
Docker/Dockerfile/Aliyun-dns-sync/File/cron.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 启动同步
|
||||
/usr/local/bin/python /aliyun-dns-sync/aliyun-dns-sync.py > /var/log/python.log
|
7
Docker/Dockerfile/Aliyun-dns-sync/File/start.sh
Normal file
7
Docker/Dockerfile/Aliyun-dns-sync/File/start.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 启动 cron
|
||||
service cron start
|
||||
|
||||
# 查看日志
|
||||
tail -f /var/log/python.log
|
15
Docker/Dockerfile/Aliyun-dns-sync/README.md
Normal file
15
Docker/Dockerfile/Aliyun-dns-sync/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 通过脚本调用阿里云接口实现动态公网IP实时与阿里云域名解析同步
|
||||
|
||||
> 使用前修改 Python 脚本内如下参数
|
||||
|
||||
```bash
|
||||
ID = '' #AccessKey ID
|
||||
SECRET = '' #AccessKey Secret
|
||||
regionId = '' #地域
|
||||
DomainName = '' #域名
|
||||
```
|
||||
|
5
Docker/Dockerfile/Busybox/Dockerfile
Normal file
5
Docker/Dockerfile/Busybox/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM busybox:latest
|
||||
|
||||
RUN echo "启动成功" > /file.txt
|
||||
|
||||
CMD ["tail","-f","/file.txt"]
|
7
Docker/Dockerfile/Busybox/README.md
Normal file
7
Docker/Dockerfile/Busybox/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Busybox
|
||||
|
||||
> 此应用于容器启动测试
|
6
Docker/Dockerfile/Cache-Registry/Dockerfile
Normal file
6
Docker/Dockerfile/Cache-Registry/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM registry:latest
|
||||
|
||||
ENV PROXY_REMOTE_URL="" \
|
||||
DELETE_ENABLED="true"
|
||||
|
||||
COPY ./entrypoint.sh /entrypoint.sh
|
56
Docker/Dockerfile/Cache-Registry/README.md
Normal file
56
Docker/Dockerfile/Cache-Registry/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 镜像仓库代理服务
|
||||
|
||||
## 优点
|
||||
|
||||
1. **加速后续拉取**:同一个镜像只需从 Docker Hub 拉取一次,后续所有团队的拉取请求都会从本地缓存服务器获取,速度极快。
|
||||
2. **节省带宽**:减少对公网 Docker Hub 的重复请求,尤其适合带宽有限或按流量计费的环境。
|
||||
|
||||
## 镜像仓库地址
|
||||
|
||||
| 站点名 | URL | 备注 |
|
||||
| :---------: | :--------------------------: | :--------------------------------------------------------: |
|
||||
| DockerHub | https://registry-1.docker.io | 拉取镜像需要带上 `library` (可能就我有这情况吧,没仔细深究) |
|
||||
| Quay | https://quay.io | |
|
||||
| Gcr | https://gcr.io | |
|
||||
| Ghcr | https://ghcr.io | |
|
||||
| K8sgcr | https://k8s.gcr.io | |
|
||||
| Registryk8s | https://registry.k8s.io | |
|
||||
|
||||
## 已构建好的镜像
|
||||
|
||||
```bash
|
||||
hub.offends.cn/registry-proxy:latest
|
||||
```
|
||||
|
||||
## 启动容器
|
||||
|
||||
[仓库地址](https://gitee.com/offends/Kubernetes/tree/main/Docker/Dockerfile/Cache-Registry)
|
||||
|
||||
- Docker
|
||||
|
||||
```bash
|
||||
docker run -itd \
|
||||
--restart always \
|
||||
-p 80:5000 \
|
||||
-v "/etc/localtime:/etc/localtime" \
|
||||
-v "/var/lib/registryproxy:/var/lib/registry" \
|
||||
-e PROXY_REMOTE_URL="https://registry-1.docker.io/library" \
|
||||
--name=registry-proxy \
|
||||
hub.offends.cn/registry-proxy:latest
|
||||
```
|
||||
|
||||
- Docker-compose
|
||||
|
||||
> 文件在本仓库当前目录下, 修改 `PROXY_REMOTE_URL` 参数后即可使用
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
- Kubernetes
|
||||
|
||||
**查看此篇文档**
|
||||
|
||||
[Kubernetes部署Registry镜像仓库缓存服务](https://gitee.com/offends/Kubernetes/tree/main/Docker/Dockerfile/Cache-Registry/README.md)
|
13
Docker/Dockerfile/Cache-Registry/docker-compose.yaml
Normal file
13
Docker/Dockerfile/Cache-Registry/docker-compose.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
version: "3"
|
||||
services:
|
||||
registryproxy:
|
||||
image: "hub.offends.cn/registry-proxy:latest"
|
||||
container_name: "registryproxy"
|
||||
restart: "always"
|
||||
volumes:
|
||||
- "/etc/localtime:/etc/localtime"
|
||||
- "/var/lib/registryproxy:/var/lib/registry"
|
||||
environment:
|
||||
- "PROXY_REMOTE_URL=http://registry:5000"
|
||||
ports:
|
||||
- "5000:5000"
|
37
Docker/Dockerfile/Cache-Registry/entrypoint.sh
Normal file
37
Docker/Dockerfile/Cache-Registry/entrypoint.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 定制缓存 Registry 镜像
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2024-06-29
|
||||
#############################################################################################
|
||||
|
||||
set -e
|
||||
|
||||
# 配置 Headers
|
||||
sed -i "/headers:/a\ Access-Control-Allow-Origin: ['*']" /etc/docker/registry/config.yml
|
||||
sed -i "/headers:/a\ Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']" /etc/docker/registry/config.yml
|
||||
sed -i "/headers:/a\ Access-Control-Expose-Headers: ['Docker-Content-Digest']" /etc/docker/registry/config.yml
|
||||
|
||||
# 检查环境变量PROXY_REMOTE_URL是否非空, 检查配置文件中变量出现的次数是否为0
|
||||
if [ -n "$PROXY_REMOTE_URL" ] && [ $(grep -c "$PROXY_REMOTE_URL" "/etc/docker/registry/config.yml") -eq 0 ]; then
|
||||
echo "proxy:" >> /etc/docker/registry/config.yml
|
||||
echo " remoteurl: $PROXY_REMOTE_URL" >> /etc/docker/registry/config.yml
|
||||
# 可以提供用户名和密码保持私密
|
||||
# echo " username: $PROXY_USERNAME" >> /etc/docker/registry/config.yml
|
||||
# echo " password: $PROXY_PASSWORD" >> /etc/docker/registry/config.yml
|
||||
echo "----- Enabled Proxy To Remote -----"
|
||||
fi
|
||||
# 判断是否开启 Registry 镜像镜像清理
|
||||
if [ "$DELETE_ENABLED" = "true" ] && [ $(grep -c "delete:" /etc/docker/registry/config.yml) -eq 0 ]; then
|
||||
sed -i '/rootdirectory:/a\ delete:' /etc/docker/registry/config.yml
|
||||
sed -i '/delete:/a\ enabled: true' /etc/docker/registry/config.yml
|
||||
echo "----- Enabled Local Storage Delete -----"
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
*.yaml|*.yml) set -- registry serve "$@" ;;
|
||||
serve|garbage-collect|help|-*) set -- registry "$@" ;;
|
||||
esac
|
||||
|
||||
exec "$@"
|
5
Docker/Dockerfile/Centos/Dockerfile
Normal file
5
Docker/Dockerfile/Centos/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM scratch
|
||||
|
||||
ADD ./centos/rootfs /
|
||||
|
||||
CMD /bin/bash
|
10
Docker/Dockerfile/Centos/README.md
Normal file
10
Docker/Dockerfile/Centos/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Centos 镜像构建
|
||||
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
||||
|
72
Docker/Dockerfile/Centos/build.sh
Normal file
72
Docker/Dockerfile/Centos/build.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 构建 Centos 系统 Docker 镜像的脚本
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2023-11-27
|
||||
#############################################################################################
|
||||
|
||||
# 镜像地址
|
||||
# 阿里云: https://mirrors.aliyun.com/centos/
|
||||
# 官方: https://www.centos.org/
|
||||
# 其他: https://vault.centos.org/
|
||||
|
||||
VERSION="7.9.2009"
|
||||
|
||||
CENTOS_VERSION="7"
|
||||
URL="https://mirrors.aliyun.com/centos/$VERSION/os/x86_64/Packages"
|
||||
RPM_VERSION="centos-release-7-9.2009.0.el7.centos.x86_64.rpm"
|
||||
|
||||
CENTOS_URL="$URL/$RPM_VERSION"
|
||||
|
||||
# 加载检测脚本
|
||||
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
||||
|
||||
function INSTALL_WGET(){
|
||||
CHECK_INSTALL wget
|
||||
}
|
||||
|
||||
# 初始化目录和文件
|
||||
function INIT_DIR(){
|
||||
CHECK_DIR ./centos/rootfs && cd ./centos
|
||||
CHECK_COMMAND_NULL rpm --root $PWD/rootfs --initdb
|
||||
SEND_INFO "初始化目录和文件完成"
|
||||
SEND_INFO "正在获取RPM文件"
|
||||
CHECK_COMMAND_NULL wget $CENTOS_URL
|
||||
|
||||
CHECK_FILE "centos-release-7-9.2009.0.el7.centos.x86_64.rpm"
|
||||
NULL_TRUE rpm -ivh --nodeps --root $PWD/rootfs --package ./$RPM_VERSION
|
||||
|
||||
# #在无法获取到软件包源的情况下使用
|
||||
# SEND_INFO "正在备份 YUM 源文件"
|
||||
# CHECK_DIR /etc/yum.repos.d/Offends
|
||||
# CHECK_COMMAND_NULL \cp -r /etc/yum.repos.d/epel.repo /etc/yum.repos.d/Offends && \cp -r /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Offends
|
||||
# # 获取需要的软件包源
|
||||
# SEND_INFO "正在获取软件包源"
|
||||
# CHECK_COMMAND_NULL wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-$CENTOS_VERSION.repo
|
||||
# CHECK_COMMAND_NULL wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-$CENTOS_VERSION.repo
|
||||
# # 清除缓存
|
||||
# SEND_INFO "正在清除缓存"
|
||||
# CHECK_COMMAND_NULL yum makecache
|
||||
# # 根据自己需求修改
|
||||
# CHECK_COMMAND_NULL sed -i 's@baseurl=.*@baseurl=https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/@' /etc/yum.repos.d/*.repo
|
||||
|
||||
SEND_INFO "正在安装基础软件包,拉取过程较慢请稍后"
|
||||
CHECK_COMMAND_NULL yum --installroot=$PWD/rootfs install yum --nogpgcheck -y
|
||||
SEND_INFO "开始构建镜像"
|
||||
CHECK_COMMAND_NULL cd .. && docker build -t centos:$VERSION .
|
||||
SEND_INFO "构建完成,镜像名称: centos:$VERSION"
|
||||
|
||||
# # 恢复 YUM 源文件
|
||||
# SEND_INFO "正在恢复 YUM 源文件"
|
||||
# CHECK_COMMAND_NULL rm -rf /etc/yum.repos.d/CentOS-Base.repo && rm -rf /etc/yum.repos.d/epel.repo
|
||||
# CHECK_COMMAND_NULL cp -r /etc/yum.repos.d/Offends/* /etc/yum.repos.d/
|
||||
}
|
||||
|
||||
|
||||
function ALL(){
|
||||
INSTALL_WGET
|
||||
INIT_DIR
|
||||
}
|
||||
|
||||
ALL
|
5
Docker/Dockerfile/Debain/Dockerfile
Normal file
5
Docker/Dockerfile/Debain/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM scratch
|
||||
|
||||
ADD rootfs.tar.xz /
|
||||
|
||||
CMD /bin/bash
|
10
Docker/Dockerfile/Debain/README.md
Normal file
10
Docker/Dockerfile/Debain/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Debain 镜像构建
|
||||
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
||||
|
48
Docker/Dockerfile/Debain/build.sh
Normal file
48
Docker/Dockerfile/Debain/build.sh
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 构建 Debian 系统 Docker 镜像的脚本
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2023-11-27
|
||||
#############################################################################################
|
||||
|
||||
# 镜像地址
|
||||
# https://docker.debian.net/
|
||||
|
||||
ROOTFS="https://github.com/debuerreotype/docker-debian-artifacts/raw"
|
||||
|
||||
VERSION="1f1e36af44a355418661956f15e39f5b04b848b6"
|
||||
|
||||
FILE="stable/rootfs.tar.xz"
|
||||
|
||||
DEBAIN=$ROOTFS/$VERSION/$FILE
|
||||
|
||||
# 加载检测脚本
|
||||
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
||||
|
||||
function INSTALL_WGET(){
|
||||
CHECK_INSTALL wget
|
||||
}
|
||||
|
||||
function INSTALL(){
|
||||
SEND_INFO "正在下载资源文件,请稍等..."
|
||||
CHECK_COMMAND_NULL wget $DEBAIN
|
||||
BUILD
|
||||
}
|
||||
|
||||
# 构建 Debian 系统
|
||||
function BUILD(){
|
||||
CHECK_FILE "rootfs.tar.xz"
|
||||
SEND_INFO "正在构建 Debian 系统,请稍等..."
|
||||
CHECK_COMMAND_NULL docker import rootfs.tar.xz debian:stable
|
||||
# docker build -t debian:stable .
|
||||
CHECK_COMMAND_NULL rm -rf rootfs.tar.xz
|
||||
SEND_INFO "构建完成,镜像名称: debian:stable"
|
||||
}
|
||||
|
||||
function ALL(){
|
||||
INSTALL_WGET
|
||||
INSTALL
|
||||
}
|
||||
|
||||
ALL
|
5
Docker/Dockerfile/Drone-Images/Dockerfile-git
Normal file
5
Docker/Dockerfile/Drone-Images/Dockerfile-git
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM alpine/git
|
||||
|
||||
LABEL maintainer="Offends <offends4@163.com>"
|
||||
|
||||
RUN apk add --no-cache bash
|
10
Docker/Dockerfile/Drone-Images/Dockerfile-minio
Normal file
10
Docker/Dockerfile/Drone-Images/Dockerfile-minio
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM alpine:latest
|
||||
|
||||
LABEL maintainer="Offends <offends4@163.com>"
|
||||
|
||||
COPY ./mc.sh .
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps \
|
||||
curl \
|
||||
&& sh ./mc.sh \
|
||||
&& apk del .build-deps
|
11
Docker/Dockerfile/Drone-Images/Dockerfile-oss
Normal file
11
Docker/Dockerfile/Drone-Images/Dockerfile-oss
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM alpine:latest
|
||||
|
||||
LABEL maintainer="Offends <offends4@163.com>"
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps \
|
||||
unzip \
|
||||
bash \
|
||||
curl \
|
||||
&& curl -O https://gosspublic.alicdn.com/ossutil/install.sh \
|
||||
&& bash install.sh && rm -rf install.sh \
|
||||
&& apk del .build-deps
|
14
Docker/Dockerfile/Drone-Images/README.md
Normal file
14
Docker/Dockerfile/Drone-Images/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Drone 基础镜像构建
|
||||
|
||||
> Dockerfile示例
|
||||
|
||||
| 文件名 | 镜像功能 | 构建示例 |
|
||||
| :--------------: | :-------------------------: | :-----------------------------------------------: |
|
||||
| Dockerfile-git | 最小化 Git 容器 | docker build -t 镜像名:标签 -f Dockerfile-git . |
|
||||
| Dockerfile-minio | 容器内自带 Minio 客户端命令 | docker build -t 镜像名:标签 -f Dockerfile-minio . |
|
||||
| Dockerfile-oss | 容器内自带 oss 客户端命令 | docker build -t 镜像名:标签 -f Dockerfile-oss . |
|
||||
|
25
Docker/Dockerfile/Drone-Images/mc.sh
Normal file
25
Docker/Dockerfile/Drone-Images/mc.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 部署 MinIO 客户端工具 mc
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2024-02-14
|
||||
#############################################################################################
|
||||
|
||||
# 判断系统架构
|
||||
if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; then
|
||||
ARCH_TYPE=linux-amd64
|
||||
elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; then
|
||||
ARCH_TYPE=linux-arm64
|
||||
else
|
||||
echo "无法识别的系统架构: $(arch)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 变量定义
|
||||
URL="https://dl.min.io/client/mc/release/$ARCH_TYPE"
|
||||
|
||||
# 下载文件
|
||||
curl -so /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc
|
||||
# 添加执行权限
|
||||
chmod 777 /usr/local/bin/mc
|
3
Docker/Dockerfile/Fio/Dockerfile
Normal file
3
Docker/Dockerfile/Fio/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add fio
|
7
Docker/Dockerfile/Fio/README.md
Normal file
7
Docker/Dockerfile/Fio/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Fio
|
||||
|
||||
> 此应用于磁盘读写性能测试
|
128
Docker/Dockerfile/Frp/.drone.yml
Normal file
128
Docker/Dockerfile/Frp/.drone.yml
Normal file
@@ -0,0 +1,128 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Build Frps
|
||||
|
||||
# 手动触发或接口触发
|
||||
trigger:
|
||||
event:
|
||||
- custom
|
||||
|
||||
# 指定架构,需在 runner 配置环境变量中指定 DRONE_RUNNER_ARCH,或自动获取
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
# 指定运行环境节点,需在 runner 配置环境变量中指定 DRONE_RUNNER_LABELS
|
||||
node:
|
||||
City: abroad
|
||||
|
||||
# 使用插件构建镜像
|
||||
steps:
|
||||
- name: Build Frps
|
||||
image: plugins/docker
|
||||
# 仅当本地不存在该镜像时才拉取
|
||||
pull: if-not-exists
|
||||
settings:
|
||||
registry:
|
||||
from_secret: REGISTRY
|
||||
username:
|
||||
from_secret: DOCKER_USERNAME
|
||||
password:
|
||||
from_secret: DOCKER_PASSWORD
|
||||
repo:
|
||||
from_secret: REPO
|
||||
# 是否禁止推送镜像
|
||||
dry_run: false
|
||||
tags:
|
||||
- frps
|
||||
# 要使用的上下文路径,默认为 git 存储库的根目录
|
||||
context: ./frps
|
||||
# 要使用的 dockerfile 路径,默认为 git 存储库的根目录
|
||||
dockerfile: ./frps/Dockerfile
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Build Frpc
|
||||
|
||||
# 手动触发或接口触发
|
||||
trigger:
|
||||
event:
|
||||
- custom
|
||||
|
||||
# 指定架构,需在 runner 配置环境变量中指定 DRONE_RUNNER_ARCH,或自动获取
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
# 指定运行环境节点,需在 runner 配置环境变量中指定 DRONE_RUNNER_LABELS
|
||||
node:
|
||||
City: abroad
|
||||
|
||||
# 使用插件构建镜像
|
||||
steps:
|
||||
- name: Build Frpc
|
||||
image: plugins/docker
|
||||
# 仅当本地不存在该镜像时才拉取
|
||||
pull: if-not-exists
|
||||
settings:
|
||||
registry:
|
||||
from_secret: REGISTRY
|
||||
username:
|
||||
from_secret: DOCKER_USERNAME
|
||||
password:
|
||||
from_secret: DOCKER_PASSWORD
|
||||
repo:
|
||||
from_secret: REPO
|
||||
# 是否禁止推送镜像
|
||||
dry_run: false
|
||||
tags:
|
||||
- frpc
|
||||
# 要使用的上下文路径,默认为 git 存储库的根目录
|
||||
context: ./frpc
|
||||
# 要使用的 dockerfile 路径,默认为 git 存储库的根目录
|
||||
dockerfile: ./frpc/Dockerfile
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Sync Ipsec Vpn Image
|
||||
|
||||
trigger:
|
||||
event:
|
||||
include:
|
||||
- custom
|
||||
|
||||
# 指定运行环境节点,需在 runner 配置环境变量中指定 DRONE_RUNNER_LABELS
|
||||
node:
|
||||
City: abroad
|
||||
|
||||
steps:
|
||||
- name: Sync Ipsec Vpn Image
|
||||
image: docker:dind
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
environment:
|
||||
DOCKER_USERNAME:
|
||||
from_secret: DOCKER_USERNAME
|
||||
DOCKER_PASSWORD:
|
||||
from_secret: DOCKER_PASSWORD
|
||||
REGISTRY:
|
||||
from_secret: REGISTRY
|
||||
REPO:
|
||||
from_secret: REPO
|
||||
commands:
|
||||
- docker pull hwdsl2/ipsec-vpn-server
|
||||
- docker login $REGISTRY -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
|
||||
- docker tag hwdsl2/ipsec-vpn-server $REPO:ipsec-vpn-server
|
||||
- docker push $REPO:ipsec-vpn-server
|
||||
|
||||
volumes:
|
||||
- name: dockersock
|
||||
host:
|
||||
path: /var/run/docker.sock
|
13
Docker/Dockerfile/Frp/Drone构建参数解释.md
Normal file
13
Docker/Dockerfile/Frp/Drone构建参数解释.md
Normal file
@@ -0,0 +1,13 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
## Drone构建参数解释
|
||||
|
||||
| 变量名 | 变量值 | 备注 |
|
||||
| :-------------: | :---------------------------------------------------: | :------------: |
|
||||
| DOCKER_USERNAME | | 镜像仓库账号 |
|
||||
| DOCKER_PASSWORD | | 镜像仓库密码 |
|
||||
| REGISTRY | registry.cn-hangzhou.aliyuncs.com | 镜像仓库地址 |
|
||||
| REPO | registry.cn-hangzhou.aliyuncs.com/<命名空间>/<镜像名> | 镜像的仓库名称 |
|
||||
|
27
Docker/Dockerfile/Frp/frpc/Dockerfile
Normal file
27
Docker/Dockerfile/Frp/frpc/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
||||
FROM alpine:latest
|
||||
|
||||
LABEL maintainer="Offends <offends4@163.com>"
|
||||
|
||||
ARG VERSION_ARG
|
||||
|
||||
ENV VERSION=${VERSION_ARG:-0.53.2}
|
||||
|
||||
RUN if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; then \
|
||||
ARCH_TYPE="amd64"; \
|
||||
elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; then \
|
||||
ARCH_TYPE="arm"; \
|
||||
else \
|
||||
ARCH_TYPE="amd64"; \
|
||||
fi \
|
||||
&& wget https://github.com/fatedier/frp/releases/download/v${VERSION}/frp_${VERSION}_linux_${ARCH_TYPE}.tar.gz \
|
||||
&& tar -zvxf frp_${VERSION}_linux_${ARCH_TYPE}.tar.gz \
|
||||
&& cp -r frp_${VERSION}_linux_${ARCH_TYPE} frp \
|
||||
&& mv /frp/frpc /usr/local/bin/ \
|
||||
&& rm -rf /frp/frps* /frp/LICENSE \
|
||||
&& rm -rf /frp_${VERSION}_linux_${ARCH_TYPE}*
|
||||
|
||||
COPY ./frpc.ini /frp/frpc.ini
|
||||
|
||||
WORKDIR /frp
|
||||
|
||||
CMD /usr/local/bin/frpc -c /frp/frpc.ini
|
24
Docker/Dockerfile/Frp/frpc/README.md
Normal file
24
Docker/Dockerfile/Frp/frpc/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# **Frpc内网穿透**
|
||||
|
||||
> Frpc 为内网穿透客户端
|
||||
>
|
||||
|
||||
## Docker构建
|
||||
|
||||
构建镜像
|
||||
|
||||
> 默认构建 0.53.2 版本
|
||||
|
||||
```bash
|
||||
docker build -t registry.cn-hangzhou.aliyuncs.com/offends/frp:frpc .
|
||||
```
|
||||
|
||||
> 手动选择构建版本
|
||||
|
||||
```bash
|
||||
docker build --build-arg VERSION_ARG=0.53.2 -t registry.cn-hangzhou.aliyuncs.com/offends/frp:frpc .
|
||||
```
|
8
Docker/Dockerfile/Frp/frpc/frpc.bat
Normal file
8
Docker/Dockerfile/Frp/frpc/frpc.bat
Normal file
@@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
if "%1" == "h" goto begin
|
||||
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
|
||||
:begin
|
||||
REM
|
||||
cd C:\frpc
|
||||
frpc -c frpc.ini
|
||||
exit
|
30
Docker/Dockerfile/Frp/frpc/frpc.ini
Normal file
30
Docker/Dockerfile/Frp/frpc/frpc.ini
Normal file
@@ -0,0 +1,30 @@
|
||||
[common]
|
||||
server_addr = {{ .Envs.FRP_SERVER_ADDR }}
|
||||
server_port = 7000
|
||||
token = 12345678
|
||||
|
||||
[windows]
|
||||
type = tcp
|
||||
local_ip = {{ .Envs.FRP_WINDOWS_IP }}
|
||||
local_port = {{ .Envs.FRP_WINDOWS_PORT }}
|
||||
remote_port = 3389
|
||||
|
||||
#liunx tcp 端口写法
|
||||
; [liunx]
|
||||
; type = tcp
|
||||
; local_ip = 127.0.0.1
|
||||
; local_port = 22
|
||||
; remote_port = 22
|
||||
|
||||
#esxi 端口写法
|
||||
; [esxi-web]
|
||||
; type = tcp
|
||||
; local_ip = {{ .Envs.FRP_ESXI_WEB__ADDR }}
|
||||
; local_port = 443
|
||||
; remote_port = 20000
|
||||
|
||||
; [esxi-902]
|
||||
; type = tcp
|
||||
; local_ip = {{ .Envs.FRP_ESXI_VSPHERE_API_ADDR }}
|
||||
; local_port = 902
|
||||
; remote_port = 902
|
21
Docker/Dockerfile/Frp/frps/404.html
Normal file
21
Docker/Dockerfile/Frp/frps/404.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>链接失败</title>
|
||||
<style>
|
||||
body {
|
||||
width: 35em;
|
||||
margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>请联系管理人员 Mr .Ding</h1>
|
||||
<p>实在抱歉一定要抓紧联系(家里停电|屋子着火|----).<br/>
|
||||
请一定要联系我.</p>
|
||||
<p>我需要知道家里的状况 <a>哈哈</a>.</p>
|
||||
<p><em>感谢您的配合.</em></p>
|
||||
</body>
|
||||
</html>
|
35
Docker/Dockerfile/Frp/frps/Dockerfile
Normal file
35
Docker/Dockerfile/Frp/frps/Dockerfile
Normal file
@@ -0,0 +1,35 @@
|
||||
FROM alpine:latest
|
||||
|
||||
LABEL maintainer="Offends <offends4@163.com>"
|
||||
|
||||
ARG VERSION_ARG
|
||||
|
||||
ENV VERSION=${VERSION_ARG:-0.53.2}
|
||||
|
||||
RUN if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; then \
|
||||
ARCH_TYPE="amd64"; \
|
||||
elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; then \
|
||||
ARCH_TYPE="arm"; \
|
||||
else \
|
||||
ARCH_TYPE="amd64"; \
|
||||
fi \
|
||||
&& wget https://github.com/fatedier/frp/releases/download/v${VERSION}/frp_${VERSION}_linux_${ARCH_TYPE}.tar.gz \
|
||||
&& tar -zvxf frp_${VERSION}_linux_${ARCH_TYPE}.tar.gz \
|
||||
&& cp -r frp_${VERSION}_linux_${ARCH_TYPE} frp \
|
||||
&& mv /frp/frps /usr/local/bin/ \
|
||||
&& rm -rf /frp/frpc* /frp/LICENSE \
|
||||
&& rm -rf /frp_${VERSION}_linux_${ARCH_TYPE}*
|
||||
|
||||
COPY ./frps.ini /frp/frps.ini
|
||||
|
||||
COPY ./404.html /frp/404.html
|
||||
|
||||
WORKDIR /frp
|
||||
|
||||
#客户端连接端口
|
||||
EXPOSE 7000
|
||||
|
||||
#frp Web端
|
||||
EXPOSE 7500
|
||||
|
||||
CMD /usr/local/bin/frps -c /frp/frps.ini
|
23
Docker/Dockerfile/Frp/frps/README.md
Normal file
23
Docker/Dockerfile/Frp/frps/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# **Frps内网穿透**
|
||||
|
||||
> Frps为内网穿透服务端
|
||||
|
||||
## Docker构建
|
||||
|
||||
构建镜像
|
||||
|
||||
> 默认构建 0.53.2 版本
|
||||
|
||||
```bash
|
||||
docker build -t registry.cn-hangzhou.aliyuncs.com/offends/frp:frps .
|
||||
```
|
||||
|
||||
> 手动选择构建版本
|
||||
|
||||
```bash
|
||||
docker build --build-arg VERSION_ARG=0.53.2 -t registry.cn-hangzhou.aliyuncs.com/offends/frp:frps .
|
||||
```
|
10
Docker/Dockerfile/Frp/frps/frps.ini
Normal file
10
Docker/Dockerfile/Frp/frps/frps.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
[common]
|
||||
bind_port = 7000
|
||||
dashboard_port = 7500
|
||||
token = 12345678
|
||||
dashboard_user = admin
|
||||
dashboard_pwd = admin
|
||||
#vhost_http_port = 80
|
||||
#vhost_https_port = 443
|
||||
custom_404_page = /frp/404.html
|
||||
max_pool_count = 5
|
20
Docker/Dockerfile/Mysql/Dockerfile
Normal file
20
Docker/Dockerfile/Mysql/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
FROM mysql:5.7
|
||||
# FROM mysql:8
|
||||
|
||||
ENV MYSQL_USER=demo \
|
||||
MYSQL_PASSWORD=demo \
|
||||
MYSQL_DATABASE=demo \
|
||||
MYSQL_ROOT_PASSWORD=root
|
||||
|
||||
COPY ./sql/* /docker-entrypoint-initdb.d/
|
||||
|
||||
# 更改配置文件
|
||||
#COPY ./my.cnf /etc/my.cnf
|
||||
|
||||
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
|
||||
|
||||
# 旧加密方式
|
||||
# --default-authentication-plugin=mysql_native_password
|
||||
# 是一种基本的身份验证插件,它使用经典的 MySQL 加密方法来存储和验证用户的密码。这意味着用户的密码以散列形式存储在数据库中,而在用户登录时,其密码将与存储的散列进行比较。
|
||||
# 新加密方式
|
||||
# --default-authentication-plugin=caching_sha2_password
|
14
Docker/Dockerfile/Mysql/Dockerfile-secrets
Normal file
14
Docker/Dockerfile/Mysql/Dockerfile-secrets
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM mysql:5.7
|
||||
# FROM mysql:8
|
||||
|
||||
ENV MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql-root-pass \
|
||||
MYSQL_USER=demo \
|
||||
MYSQL_DATABASE=demo \
|
||||
MYSQL_PASSWORD_FILE=/run/secrets/mysql-demo-pass
|
||||
|
||||
COPY ./sql/* /docker-entrypoint-initdb.d/
|
||||
|
||||
# 更改配置文件
|
||||
#COPY ./my.cnf /etc/my.cnf
|
||||
|
||||
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
|
21
Docker/Dockerfile/Mysql/README.md
Normal file
21
Docker/Dockerfile/Mysql/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Mysql 镜像构建
|
||||
|
||||
- 自动初始化 Mysql 数据库, 构建示例
|
||||
|
||||
```bash
|
||||
docker build -t <镜像名:标签> .
|
||||
```
|
||||
|
||||
- Mysql 通过 Secrets 隐藏构建账户密码, 示例
|
||||
|
||||
[Mysql-Secrets 使用](https://gitee.com/offends/Kubernetes/tree/main/Docker/Docker%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3/Mysql-secrets%E4%BD%BF%E7%94%A8.md)
|
||||
|
||||
```bash
|
||||
docker build -t <镜像名:标签> --file=./Dockerfile-secrets .
|
||||
```
|
||||
|
||||
|
1
Docker/Dockerfile/Mysql/my.cnf
Normal file
1
Docker/Dockerfile/Mysql/my.cnf
Normal file
@@ -0,0 +1 @@
|
||||
# 写入配置文件指定内容
|
1
Docker/Dockerfile/Mysql/sql/01_init_offends.sql
Normal file
1
Docker/Dockerfile/Mysql/sql/01_init_offends.sql
Normal file
@@ -0,0 +1 @@
|
||||
-- 初始化基础 sql
|
16
Docker/Dockerfile/Nginx/Dockerfile
Normal file
16
Docker/Dockerfile/Nginx/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
# 推荐使用最新版,漏洞会较少,通过漏洞扫描的几率较大
|
||||
#FROM nginx:latest
|
||||
FROM nginx:alpine
|
||||
|
||||
# 初始化 NGINX 配置文件
|
||||
ENV NGINX_ENVSUBST_TEMPLATE_DIR=/etc/nginx/templates \
|
||||
NGINX_ENVSUBST_TEMPLATE_SUFFIX=.template \
|
||||
NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx/conf.d
|
||||
|
||||
COPY ./templates/*.template /etc/nginx/templates/
|
||||
|
||||
COPY ./nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# 自定义初始化变量
|
||||
ENV NGINX_PORT=80 \
|
||||
NGINX_HOST=localhost
|
16
Docker/Dockerfile/Nginx/Dockerfile-node
Normal file
16
Docker/Dockerfile/Nginx/Dockerfile-node
Normal file
@@ -0,0 +1,16 @@
|
||||
# 多阶段构建
|
||||
FROM node:14 as build
|
||||
|
||||
COPY . /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN npm config set registry https://registry.npmmirror.com \
|
||||
&& npm install \
|
||||
&& npm run build:prod
|
||||
|
||||
FROM nginx:alpine
|
||||
|
||||
COPY --from=build /app/dist /app/www
|
||||
|
||||
COPY ./web.conf /etc/nginx/conf.d/default.conf
|
12
Docker/Dockerfile/Nginx/README.md
Normal file
12
Docker/Dockerfile/Nginx/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
*
|
||||
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Nginx 镜像构建
|
||||
|
||||
> Dockerfile示例
|
||||
|
||||
| 文件名 | 示例作用 | 构建示例 |
|
||||
| :-------------: | :-------------------------------------: | :----------------------------------------------: |
|
||||
| Dockerfile | 示例如何通过环境变量更改Nginx配置文件 | docker build -t 镜像名:标签 . |
|
||||
| Dockerfile-ndoe | 示例如何通过过阶段构建,构建Npm前端代码 | docker build -t 镜像名:标签 -f Dockerfile-node . |
|
31
Docker/Dockerfile/Nginx/nginx.conf
Normal file
31
Docker/Dockerfile/Nginx/nginx.conf
Normal file
@@ -0,0 +1,31 @@
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log notice;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
17
Docker/Dockerfile/Nginx/templates/default.conf.template
Normal file
17
Docker/Dockerfile/Nginx/templates/default.conf.template
Normal file
@@ -0,0 +1,17 @@
|
||||
server {
|
||||
listen ${NGINX_PORT};
|
||||
listen [::]:${NGINX_PORT};
|
||||
server_name ${NGINX_HOST};
|
||||
|
||||
#access_log /var/log/nginx/host.access.log main;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
}
|
8
Docker/Dockerfile/Nginx/web.conf
Normal file
8
Docker/Dockerfile/Nginx/web.conf
Normal file
@@ -0,0 +1,8 @@
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
location / {
|
||||
root /app/www;
|
||||
index index.html index.htm;
|
||||
}
|
||||
}
|
56
Docker/Docs/Bitnami部署Mysql主从.md
Normal file
56
Docker/Docs/Bitnami部署Mysql主从.md
Normal file
@@ -0,0 +1,56 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Bitnami部署Mysql主从
|
||||
|
||||
1. 创建持久化目录
|
||||
|
||||
```bash
|
||||
mkdir -p /opt/mysql/data
|
||||
chmod 777 /opt/mysql/data
|
||||
```
|
||||
|
||||
2. 部署 Master 容器
|
||||
|
||||
```bash
|
||||
docker run --name mysql-master --restart=always \
|
||||
-p 3306:3306 \
|
||||
-v /opt/mysql/data:/bitnami/mysql/data \
|
||||
-e MYSQL_ROOT_PASSWORD=root \
|
||||
-e MYSQL_REPLICATION_MODE=master \
|
||||
-e MYSQL_REPLICATION_USER=slave \
|
||||
-e MYSQL_REPLICATION_PASSWORD=slave_password \
|
||||
-e MYSQL_AUTHENTICATION_PLUGIN=mysql_native_password \
|
||||
-d bitnami/mysql:latest
|
||||
```
|
||||
|
||||
3. 部署 Slave 容器
|
||||
|
||||
```bash
|
||||
docker run --name mysql-slave --restart=always \
|
||||
-p 3306:3306 \
|
||||
-v /opt/mysql/data:/bitnami/mysql/data \
|
||||
-e MYSQL_MASTER_HOST=<MYSQL_MASTER_HOST> \
|
||||
-e MYSQL_MASTER_ROOT_PASSWORD=root \
|
||||
-e MYSQL_MASTER_PORT_NUMBER=3306 \
|
||||
-e MYSQL_REPLICATION_MODE=slave \
|
||||
-e MYSQL_REPLICATION_USER=slave \
|
||||
-e MYSQL_REPLICATION_PASSWORD=slave_password \
|
||||
-e MYSQL_AUTHENTICATION_PLUGIN=mysql_native_password \
|
||||
-d bitnami/mysql:latest
|
||||
```
|
||||
|
||||
4. 进入 Slave 容器
|
||||
|
||||
```bash
|
||||
docker exec -it mysql-slave bash
|
||||
mysql -u root -proot
|
||||
```
|
||||
|
||||
5. 查看同步状态
|
||||
|
||||
```bash
|
||||
show slave status\G;
|
||||
```
|
||||
|
||||
> 切记请勿在主使用清空 GTID 信息命令,会使主从状态失效
|
||||
|
80
Docker/Docs/Centos安装Docker.md
Normal file
80
Docker/Docs/Centos安装Docker.md
Normal file
@@ -0,0 +1,80 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker网络安装
|
||||
|
||||
> 整体来说各系统安装方式都相差不大,那么咱们这里只举例 Centos 安装 Docker 形式
|
||||
>
|
||||
> [官网安装文档](https://docs.docker.com/engine/install/)
|
||||
|
||||
## 开始部署
|
||||
|
||||
1. 卸载就办 Docker
|
||||
|
||||
```bash
|
||||
sudo yum remove docker \
|
||||
docker-client \
|
||||
docker-client-latest \
|
||||
docker-common \
|
||||
docker-latest \
|
||||
docker-latest-logrotate \
|
||||
docker-logrotate \
|
||||
docker-engine
|
||||
```
|
||||
|
||||
2. 设置存储库
|
||||
|
||||
```bash
|
||||
yum install -y yum-utils
|
||||
```
|
||||
|
||||
```bash
|
||||
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
|
||||
```
|
||||
|
||||
> 国内源
|
||||
>
|
||||
> ```bash
|
||||
> yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
|
||||
> ```
|
||||
|
||||
3. 安装最新版
|
||||
|
||||
```bash
|
||||
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
```
|
||||
|
||||
> 安装特定版本
|
||||
>
|
||||
> - 查看版本库
|
||||
>
|
||||
> ```bash
|
||||
> yum list docker-ce --showduplicates | sort -r
|
||||
> ```
|
||||
>
|
||||
> - 安装
|
||||
>
|
||||
> ```bash
|
||||
> sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
> ```
|
||||
|
||||
4. 启动
|
||||
|
||||
```bash
|
||||
systemctl enable docker
|
||||
systemctl start docker
|
||||
```
|
||||
|
||||
## 卸载 Docker
|
||||
|
||||
1. 卸载软件包
|
||||
|
||||
```bash
|
||||
yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
|
||||
```
|
||||
|
||||
2. 清理文件
|
||||
|
||||
```bash
|
||||
rm -rf /var/lib/docker
|
||||
rm -rf /var/lib/containerd
|
||||
```
|
82
Docker/Docs/Docker-fio磁盘读写测试.md
Normal file
82
Docker/Docs/Docker-fio磁盘读写测试.md
Normal file
@@ -0,0 +1,82 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker-fio磁盘读写测试
|
||||
|
||||
[官方文档](https://fio.readthedocs.io/en/latest/fio_doc.html)
|
||||
|
||||
1. 拉取测试工具镜像
|
||||
|
||||
```bash
|
||||
docker pull registry.cn-hangzhou.aliyuncs.com/offends/fio:latest
|
||||
```
|
||||
|
||||
2. 启动并进入容器
|
||||
|
||||
> 为了更好的测试磁盘读写速率我们挂载 /data 目录进行测试
|
||||
|
||||
```bash
|
||||
docker run --name disktest \
|
||||
-it --rm -v /data/disk_test:/data/disk_test \
|
||||
registry.cn-hangzhou.aliyuncs.com/offends/fio:latest \
|
||||
sh
|
||||
```
|
||||
|
||||
3. 开始测试
|
||||
|
||||
- 随机写
|
||||
|
||||
```bash
|
||||
fio --ioengine=libaio --runtime=300 --numjobs=2 --iodepth=64 --bs=4k --size=2G --rw=randwrite --filename=/data/disk_test --time_based=1 --direct=1 --name=test --group_reporting --cpus_allowed=3 --cpus_allowed_policy=split
|
||||
```
|
||||
|
||||
- 顺序写
|
||||
|
||||
```bash
|
||||
fio --ioengine=libaio -runtime=300 --numjobs=2 --iodepth=64 --bs=1024k --size=10G --rw=write --filename=/data/disk_test --time_based=1 --direct=1 --name=test --group_reporting --cpus_allowed=3 --cpus_allowed_policy=split
|
||||
```
|
||||
|
||||
4. 查看结果
|
||||
|
||||
> 随机写看(IOPS)
|
||||
>
|
||||
> 顺序写看(吞吐量BW)
|
||||
|
||||
# 命令参数
|
||||
|
||||
| 参数 | 描述 |
|
||||
| -------------------- | ------------------------------------------------------------ |
|
||||
| --debug=options | 启用调试日志记录,可以选择启用不同类型的调试信息,比如进程、文件、IO等等。 |
|
||||
| --parse-only | 仅解析选项,不执行任何IO操作。 |
|
||||
| --output | 将输出写入文件。 |
|
||||
| --bandwidth-log | 生成带宽日志。 |
|
||||
| --minimal | 生成最小化(简洁)的输出。 |
|
||||
| --output-format=type | 指定输出格式,可以是简洁、JSON等。 |
|
||||
| --terse-version=type | 设置简洁版本输出格式。 |
|
||||
| --version | 打印版本信息并退出。 |
|
||||
| --help | 打印帮助信息。 |
|
||||
| --cpuclock-test | 执行CPU时钟的测试/验证。 |
|
||||
| --crctest=[type] | 测试校验和功能的速度。 |
|
||||
| --cmdhelp=cmd | 打印命令帮助,使用"all"可以查看所有命令。 |
|
||||
| --enghelp=engine | 打印IO引擎的帮助信息,或者列出可用的IO引擎。 |
|
||||
| --enghelp=engine,cmd | 打印特定IO引擎命令的帮助信息。 |
|
||||
| --showcmd | 将作业文件转换为命令行选项。 |
|
||||
| --eta=when | 指定何时打印ETA(预计完成时间)估计值。 |
|
||||
| --eta-newline=time | 每个 'time' 时间段强制换行显示ETA。 |
|
||||
| --status-interval=t | 每个 't' 时间段强制完整状态转储。 |
|
||||
| --readonly | 打开安全只读检查,防止写入。 |
|
||||
| --section=name | 只运行作业文件中指定的部分,可以指定多个部分。 |
|
||||
| --alloc-size=kb | 将smalloc池的大小设置为指定的kb数(默认为16384)。 |
|
||||
| --warnings-fatal | Fio解析器警告变为致命错误。 |
|
||||
| --max-jobs=nr | 支持的最大线程/进程数。 |
|
||||
| --server=args | 启动后端fio服务器。 |
|
||||
| --daemonize=pidfile | 后台运行fio服务器,将PID写入文件。 |
|
||||
| --client=hostname | 与远程后端fio服务器通信。 |
|
||||
| --remote-config=file | 告诉fio服务器加载本地作业文件。 |
|
||||
| --idle-prof=option | 报告系统或每CPU基础的CPU空闲情况或运行单位工作校准。 |
|
||||
| --inflate-log=log | 解压缩并输出压缩日志。 |
|
||||
| --trigger-file=file | 当文件存在时执行触发命令。 |
|
||||
| --trigger-timeout=t | 在指定的时间执行触发器。 |
|
||||
| --trigger=cmd | 将此命令设置为本地触发器。 |
|
||||
| --trigger-remote=cmd | 将此命令设置为远程触发器。 |
|
||||
| --aux-path=path | 使用此路径作为fio生成文件的路径。 |
|
||||
|
188
Docker/Docs/DockerHub上传双架构镜像.md
Normal file
188
Docker/Docs/DockerHub上传双架构镜像.md
Normal file
@@ -0,0 +1,188 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# DockerHub上传双架构镜像
|
||||
|
||||
## Docker manifest 推送双架构镜像
|
||||
|
||||
[官网文档](https://docs.docker.com/engine/reference/commandline/manifest/)
|
||||
|
||||
1. 构建并推送镜像
|
||||
|
||||
- X85执行
|
||||
|
||||
```bash
|
||||
docker build -t offends/demo-x86:v1 .
|
||||
docker push offends/demo-x86:v1
|
||||
```
|
||||
|
||||
- arm执行
|
||||
|
||||
```bash
|
||||
docker build -t offends/demo-arm:v1 .
|
||||
docker push offends/demo-arm:v1
|
||||
```
|
||||
|
||||
2. 创建 manifest
|
||||
|
||||
```bash
|
||||
docker manifest create offends/demo:v1 \
|
||||
offends/demo-x86:v1 \
|
||||
offends/demo-arm:v1
|
||||
```
|
||||
|
||||
3. 为镜像指定架构
|
||||
|
||||
```bash
|
||||
docker manifest annotate offends/demo-x86:v1 \
|
||||
offends/demo-x86:v1 \
|
||||
--os linux --arch x86_64
|
||||
|
||||
docker manifest annotate offends/demo-arm:v1 \
|
||||
offends/demo-arm:v1 \
|
||||
--os linux --arch arm64 --variant v8
|
||||
```
|
||||
|
||||
4. 查看
|
||||
|
||||
```bash
|
||||
docker manifest inspect offends/demo:v1
|
||||
```
|
||||
|
||||
5. 推送
|
||||
|
||||
```bash
|
||||
docker manifest push offends/demo:v1
|
||||
```
|
||||
|
||||
## Docker Buildx 推送双架构镜像
|
||||
|
||||
[Buildx二进制文件下载](https://github.com/docker/buildx/releases)
|
||||
|
||||
[模拟仓库文档](https://github.com/tonistiigi/binfmt)
|
||||
|
||||
[官网文档](https://docs.docker.com/build/building/multi-platform/)
|
||||
|
||||
1. 安装 Buildx
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.docker/cli-plugins
|
||||
mv buildx-v*.linux-amd64 ~/.docker/cli-plugins/docker-buildx
|
||||
chmod +x ~/.docker/cli-plugins/docker-buildx
|
||||
docker buildx version
|
||||
```
|
||||
|
||||
2. 添加模拟仓库
|
||||
|
||||
```bash
|
||||
docker run --privileged --rm tonistiigi/binfmt --install all
|
||||
```
|
||||
|
||||
> 内核版本需要升级,如果过低无法添加成功
|
||||
|
||||
3. 查看
|
||||
|
||||
```bash
|
||||
docker buildx ls
|
||||
#一下是输出
|
||||
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
|
||||
default * docker
|
||||
default default running v0.8+unknown linux/amd64, linux/386, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6
|
||||
```
|
||||
|
||||
4. 创建 builder 示例
|
||||
|
||||
```bash
|
||||
docker buildx create --name dmeo --use
|
||||
```
|
||||
|
||||
5. 构建混合建构镜像
|
||||
|
||||
```bash
|
||||
docker buildx build --platform linux/amd64,linux/arm64/v8 -t demo:v1 --push .
|
||||
```
|
||||
|
||||
## Docker Buildx使用私有仓库 推送双架构镜像
|
||||
|
||||
### 部署私有镜像仓库
|
||||
|
||||
[Docker hub文档](https://docs.docker.com/registry/)
|
||||
|
||||
[GitHub文档](https://github.com/distribution/distribution)
|
||||
|
||||
1. 启动镜像仓库
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name docker-registry \
|
||||
--restart=always \
|
||||
-p 5000:5000 \
|
||||
-v /root/private-registry:/var/lib/registry \
|
||||
registry
|
||||
```
|
||||
|
||||
2. 将本机Docker添加非安全仓库
|
||||
|
||||
> Buildx 只允许 https 协议的镜像仓库使用,这里的方法之建议测试使用
|
||||
|
||||
```bash
|
||||
cat > /etc/docker/daemon.json <<EOF
|
||||
{
|
||||
"experimental": true,
|
||||
"insecure-registries": ["192.168.1.10:5000"]
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
3. 重启 docker 进程启用
|
||||
|
||||
```bash
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
4. 将 buildkit 镜像推送到私仓
|
||||
|
||||
```bash
|
||||
docker tag moby/buildkit:buildx-stable-1 192.168.1.10:5000/buildkit:buildx-stable-1
|
||||
docker push 192.168.1.10:5000/buildkit:buildx-stable-1
|
||||
```
|
||||
|
||||
5. 新增 buildkit 私仓配置
|
||||
|
||||
```bash
|
||||
cat > /etc/buildkit/buildkitd.toml << EOF
|
||||
debug = true
|
||||
[registry."192.168.1.10:5000"]
|
||||
http = true
|
||||
insecure = true
|
||||
EOF
|
||||
```
|
||||
|
||||
6. 创建 builder
|
||||
|
||||
```bash
|
||||
docker buildx create --use \
|
||||
--name builder \
|
||||
--driver-opt image=192.168.1.10:5000/buildkit:buildx-stable-1 \
|
||||
--config /etc/buildkit/buildkitd.toml
|
||||
```
|
||||
|
||||
7. 构建混合建构镜像
|
||||
|
||||
```bash
|
||||
docker buildx build --platform linux/amd64,linux/arm64/v8 -t 192.168.1.10:5000/demo:v1 --push .
|
||||
```
|
||||
|
||||
8. 查看
|
||||
|
||||
```bash
|
||||
curl http://192.168.1.10:5000/v2/_catalog
|
||||
```
|
||||
|
||||
### 清理
|
||||
|
||||
删除构建器实例
|
||||
|
||||
```bash
|
||||
docker buildx rm builder
|
||||
```
|
||||
|
63
Docker/Docs/Docker上下文配置.md
Normal file
63
Docker/Docs/Docker上下文配置.md
Normal file
@@ -0,0 +1,63 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker 上下文
|
||||
|
||||
## 基础命令
|
||||
|
||||
> 示例新上下文名为: docker-node2
|
||||
|
||||
- 查看当前上下文
|
||||
|
||||
```bahs
|
||||
docker context ls
|
||||
```
|
||||
|
||||
- 详细查看上下文信息
|
||||
|
||||
```bash
|
||||
docker context inspect default
|
||||
```
|
||||
|
||||
- 创建新的上下文
|
||||
|
||||
```bash
|
||||
docker context create docker-node2 --docker host=tcp://docker:2375
|
||||
```
|
||||
|
||||
- 切换上下文
|
||||
|
||||
```bash
|
||||
docker context use docker-node2
|
||||
```
|
||||
|
||||
> 通过变量切换
|
||||
>
|
||||
> ```bash
|
||||
> export DOCKER_CONTEXT=docker-node2
|
||||
> ```
|
||||
>
|
||||
> 全局`--context`标志覆盖上下文
|
||||
>
|
||||
> ```bash
|
||||
> docker --context production container ls
|
||||
> ```
|
||||
|
||||
- 导出上下文
|
||||
|
||||
```bash
|
||||
docker context export docker-node2
|
||||
```
|
||||
|
||||
- 导入上下文
|
||||
|
||||
```bash
|
||||
docker context import docker-node2 docker-node2.dockercontext
|
||||
```
|
||||
|
||||
- 更新上下文
|
||||
|
||||
```bash
|
||||
docker context update docker-node2 --description "Test context"
|
||||
```
|
||||
|
||||
|
90
Docker/Docs/Docker使用GPU.md
Normal file
90
Docker/Docs/Docker使用GPU.md
Normal file
@@ -0,0 +1,90 @@
|
||||
> 本文作者丁辉
|
||||
|
||||
# GPU容器化基础环境准备
|
||||
|
||||
## Linux下载并安装GPU驱动(根据自身环境情况而定)
|
||||
|
||||
[请查看此文档](https://gitee.com/offends/Kubernetes/blob/main/GPU/Linux%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85GPU%E9%A9%B1%E5%8A%A8.md)
|
||||
|
||||
## 安装 NVIDIA 驱动程序 nvidia-container-toolkit
|
||||
|
||||
[官方文档](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
|
||||
|
||||
- **Centos**
|
||||
|
||||
配置生产存储库
|
||||
|
||||
```bash
|
||||
curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | \
|
||||
tee /etc/yum.repos.d/nvidia-container-toolkit.repo
|
||||
```
|
||||
|
||||
配置存储库以使用实验包(可选)
|
||||
|
||||
```bash
|
||||
yum-config-manager --enable nvidia-container-toolkit-experimental
|
||||
```
|
||||
|
||||
安装 NVIDIA Container Toolkit 软件包
|
||||
|
||||
```bash
|
||||
yum install -y nvidia-container-toolkit
|
||||
```
|
||||
|
||||
- **Ubuntu**
|
||||
|
||||
配置生产存储库
|
||||
|
||||
```bash
|
||||
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
|
||||
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
|
||||
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
|
||||
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
|
||||
```
|
||||
|
||||
配置存储库以使用实验包(可选)
|
||||
|
||||
```bash
|
||||
sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list
|
||||
```
|
||||
|
||||
安装 NVIDIA Container Toolkit 软件包
|
||||
|
||||
```bash
|
||||
apt-get update && apt-get install -y nvidia-container-toolkit
|
||||
```
|
||||
|
||||
## 容器对接GPU
|
||||
|
||||
> 以 Docker 运行时举例
|
||||
|
||||
1. 使用 `nvidia-ctk` 修改配置文件
|
||||
|
||||
```bash
|
||||
nvidia-ctk runtime configure --nvidia-set-as-default
|
||||
```
|
||||
|
||||
> 无需担心此命令会覆盖源有的配置文件内容, 它只会通过修改来改变你当前的配置文件内容
|
||||
|
||||
**参数解释**
|
||||
|
||||
| 参数 | 描述 | 使用 |
|
||||
| :-----------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
|
||||
| `--runtime=` | 指定当前容器运行时: docker,containerd,crio 等(默认会自动选择当前容器运行时) | `nvidia-ctk runtime configure --runtime=docker` |
|
||||
| `--config=` | 指定容器运行时的配置文件的位置 | `nvidia-ctk runtime configure --config=/etc/docker/daemon.json` |
|
||||
| `--nvidia-set-as-default` | 指定 NVIDIA 容器运行时作为默认运行时 | `nvidia-ctk runtime configure --nvidia-set-as-default` |
|
||||
|
||||
2. 重启服务
|
||||
|
||||
```bash
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
3. 测试
|
||||
|
||||
```bash
|
||||
docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
|
||||
```
|
||||
|
||||
> 查看是否成功打印 GPU 信息
|
||||
|
68
Docker/Docs/Docker使用Tor实现匿名通信.md
Normal file
68
Docker/Docs/Docker使用Tor实现匿名通信.md
Normal file
@@ -0,0 +1,68 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker使用Tor实现匿名通信
|
||||
|
||||
## 介绍
|
||||
|
||||
Tor(The Onion Router)是一种免费的开源软件,用于实现匿名通信。它通过全球范围内的一系列自愿维护的节点或“路由器”来转发和加密用户的互联网流量,从而隐藏用户的身份和位置。
|
||||
|
||||
[官方文档](https://community.torproject.org/onion-services/setup/install/)
|
||||
|
||||
## 开始部署
|
||||
|
||||
> 准备一个 Nginx 服务,部署 Tor 实现匿名通信 Nginx
|
||||
>
|
||||
> Nginx访问地址:192.168.1.10:80
|
||||
|
||||
1. 创建持久化目录
|
||||
|
||||
```bash
|
||||
mkdir -p $HOME/tor-data
|
||||
```
|
||||
|
||||
2. 目录授权
|
||||
|
||||
```bash
|
||||
chmod 700 $HOME/tor-data
|
||||
chown 100:65533 $HOME/tor-data
|
||||
```
|
||||
|
||||
3. 编写配置文件
|
||||
|
||||
```bash
|
||||
vi $HOME/tor-data/torrc
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
Log notice file /var/log/tor/notices.log
|
||||
SOCKSPort 0
|
||||
HiddenServiceNonAnonymousMode 1
|
||||
HiddenServiceSingleHopMode 1
|
||||
# 配置代理
|
||||
#Socks5Proxy sslocal-rust:1080
|
||||
HiddenServiceDir /var/lib/tor/nginx
|
||||
HiddenServicePort 80 192.168.1.10:80
|
||||
```
|
||||
|
||||
4. 启动容器
|
||||
|
||||
```bash
|
||||
docker run -itd \
|
||||
--restart always \
|
||||
-v $HOME/tor-data:/var/lib/tor \
|
||||
-v $HOME/tor-data:/etc/tor \
|
||||
--name=tor \
|
||||
osminogin/tor-simple:latest
|
||||
```
|
||||
|
||||
5. 查看 hostname
|
||||
|
||||
```bash
|
||||
cat $HOME/tor-data/nginx/hostname
|
||||
```
|
||||
|
||||
6. 通过匿名浏览器访问
|
||||
|
||||
> xxx.onion
|
117
Docker/Docs/Docker常用命令及参数.md
Normal file
117
Docker/Docs/Docker常用命令及参数.md
Normal file
@@ -0,0 +1,117 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker基础命令
|
||||
|
||||
> 当然太简单的咱们就不记了,闭眼都会
|
||||
|
||||
## 基础命令
|
||||
|
||||
- 查看指定 Docker 镜像的历史记录,这个命令可以帮助你了解镜像是如何构建的
|
||||
|
||||
```bash
|
||||
docker image history app:v1
|
||||
```
|
||||
|
||||
## Docker镜像批量打包
|
||||
|
||||
第一种
|
||||
|
||||
```bash
|
||||
docker save $(docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o images.tar
|
||||
```
|
||||
|
||||
第二种
|
||||
|
||||
> 将需要统一打包的镜像写在文件内
|
||||
|
||||
```bash
|
||||
cat > images.txt <<EOF
|
||||
nginx:alpine
|
||||
nginx:latest
|
||||
EOF
|
||||
```
|
||||
|
||||
打包
|
||||
|
||||
```bash
|
||||
docker save -o images.tar.gz $(cat images.txt)
|
||||
```
|
||||
|
||||
## 清理资源命令
|
||||
|
||||
- 批量删除 Exited 容器
|
||||
|
||||
```bash
|
||||
docker rm $(docker ps -q -f status=exited)
|
||||
```
|
||||
|
||||
- 移除所有没有使用的镜像
|
||||
|
||||
```bash
|
||||
docker image prune -a
|
||||
```
|
||||
|
||||
> 跳过警告提示:`--force`或`-f`
|
||||
>
|
||||
> ```bash
|
||||
> docker image prune -f
|
||||
> ```
|
||||
>
|
||||
> 清理所有无用的镜像
|
||||
>
|
||||
> ```bash
|
||||
> docker image prune --all --force
|
||||
> ```
|
||||
>
|
||||
> 超过24小时创建的镜像
|
||||
>
|
||||
> ```bash
|
||||
> docker image prune -a --filter "until=24h"
|
||||
> ```
|
||||
|
||||
- 清理不再使用的移除容器
|
||||
|
||||
```bash
|
||||
docker container prune
|
||||
```
|
||||
|
||||
- 移除卷
|
||||
|
||||
```bash
|
||||
docker volume prune
|
||||
```
|
||||
|
||||
- 移除网络
|
||||
|
||||
```bash
|
||||
docker network prune
|
||||
```
|
||||
|
||||
- 清理卷
|
||||
|
||||
```bash
|
||||
docker system prune --volumes
|
||||
```
|
||||
|
||||
- 用于清理 Docker 系统中不再使用的资源,包括容器、镜像、网络和数据卷
|
||||
|
||||
```bash
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
## 基本构建参数
|
||||
|
||||
| 参数 | 描述 | 用法示例 |
|
||||
| ------------------------- | ------------------------------------------------------------ | --------------------------------------------------- |
|
||||
| `--target` | 选择构建过程中的目标阶段(Stage)。 | `docker build --target my-stage .` |
|
||||
| `--no-cache` | 强制忽略缓存,每个指令都将重新执行。 | `docker build --no-cache .` |
|
||||
| `--build-arg` | 设置构建过程中的参数变量。 | `docker build --build-arg MY_VAR=value .` |
|
||||
| `--squash` | 合并镜像的历史记录以减小镜像层级数和总体积。 | `docker build --squash -t myimage:latest .` |
|
||||
| `--disable-content-trust` | 在执行 `docker push` 和 `docker pull` 等命令时禁用内容信任。 | `docker build --disable-content-trust -t myimage .` |
|
||||
|
||||
## 启动参数
|
||||
|
||||
| 参数 | 描述 | 用法示例 |
|
||||
| ----------------- | -------------------------------------- | ------------------------------------ |
|
||||
| `--cpus=2` | 限制容器使用的 CPU 核心数量为 2 个。 | `docker run --cpus=2 myimage` |
|
||||
| `--memory="200m"` | 限制容器可用的内存为 200 兆字节 (MB)。 | `docker run --memory="200m" myimage` |
|
74
Docker/Docs/Docker常用配置文件配置.md
Normal file
74
Docker/Docs/Docker常用配置文件配置.md
Normal file
@@ -0,0 +1,74 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker常用配置文件配置
|
||||
|
||||
## 更改IP池
|
||||
|
||||
- 添加如下参数
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"default-address-pools" : [
|
||||
{
|
||||
"base" : "192.168.0.0/16",
|
||||
"size" : 24
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 指定的 Cgroups 驱动程序
|
||||
|
||||
- 添加如下参数
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
```bash
|
||||
{
|
||||
"exec-opts": ["native.cgroupdriver=systemd"]
|
||||
}
|
||||
```
|
||||
|
||||
- 验证
|
||||
|
||||
```bash
|
||||
docker info|grep "Cgroup Driver"
|
||||
```
|
||||
|
||||
## Docker启用实验性CLI功能
|
||||
|
||||
**第一种**
|
||||
|
||||
- 客户端开启
|
||||
|
||||
```bash
|
||||
vi ~/.docker/config.json
|
||||
```
|
||||
|
||||
```bash
|
||||
{
|
||||
"experimental": "enabled"
|
||||
}
|
||||
```
|
||||
|
||||
**第二种**
|
||||
|
||||
- 服务端开启
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
```bash
|
||||
{
|
||||
"experimental": true
|
||||
}
|
||||
```
|
||||
|
||||
|
23
Docker/Docs/Docker快速部署LobeChat.md
Normal file
23
Docker/Docs/Docker快速部署LobeChat.md
Normal file
@@ -0,0 +1,23 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker快速部署LobeChat
|
||||
|
||||
[Github](https://github.com/lobehub/lobe-chat) [官方文档](https://lobehub.com/zh/features) [官方部署文档](https://lobehub.com/zh/docs/self-hosting/platform/docker)
|
||||
|
||||
[OpenAi-Api-keys页面](https://platform.openai.com/api-keys)
|
||||
|
||||
```
|
||||
docker run -d -p 3210:3210 \
|
||||
-e OPENAI_API_KEY=sk-xxxx \
|
||||
-e ACCESS_CODE=lobe66 \
|
||||
--name lobe-chat \
|
||||
lobehub/lobe-chat
|
||||
```
|
||||
|
||||
**参数解释**
|
||||
|
||||
- `OPENAI_API_KEY`:这是用于访问 OpenAI 服务的 API 密钥。这个密钥用于验证请求的身份,并确保请求是由授权用户发起的。
|
||||
|
||||
- `OPENAI_PROXY_URL`:这是一个代理服务器的 URL,用于将请求重定向到指定的地址。这可以用于在请求 OpenAI API 时绕过直接访问限制,或者用于增加安全性。
|
||||
|
||||
- `ACCESS_CODE`:这是一个访问代码,可能用于程序内部的身份验证或控制访问某些功能。
|
33
Docker/Docs/Docker更改IP池.md
Normal file
33
Docker/Docs/Docker更改IP池.md
Normal file
@@ -0,0 +1,33 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker更改IP池
|
||||
|
||||
1. 更改配置文件
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
{
|
||||
"default-address-pools" : [
|
||||
{
|
||||
"base" : "192.168.0.0/16",
|
||||
"size" : 24
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
2. 重启 Docker
|
||||
|
||||
```bash
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
99
Docker/Docs/Docker构建镜像.md
Normal file
99
Docker/Docs/Docker构建镜像.md
Normal file
@@ -0,0 +1,99 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker 构建镜像
|
||||
|
||||
> Docker 构建镜像有很多门道,今天咱就来说道说道,直接实际演示
|
||||
>
|
||||
> 为了方便简单演示,咱们就随便打包一份文件当作示例好了
|
||||
|
||||
## 多阶段构建
|
||||
|
||||
- 编写 Dockerfile
|
||||
|
||||
> 使用 AS 参数,后面定义名称
|
||||
>
|
||||
> 第二个容器直接 COPY 第一个容器所构建好的文件包使用
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
```dockerfile
|
||||
FROM alpine AS builder
|
||||
|
||||
RUN apk add git \
|
||||
&& git clone https://gitee.com/offends/Docs.git \
|
||||
&& tar -cvf Docker-Template.tar ./Docker-Template
|
||||
|
||||
FROM alpine
|
||||
|
||||
COPY --from=builder /Docker-Template.tar /
|
||||
```
|
||||
|
||||
开始构建
|
||||
|
||||
```bash
|
||||
docker build -t app:v1 .
|
||||
```
|
||||
|
||||
## 多阶段构建,选定构建容器
|
||||
|
||||
- 编写 Dockerfile
|
||||
|
||||
> 当我们在一个 Dockerfile 中定义了多个容器构建,这里我门可以使用 `--target` 参数指定特定的容器构建
|
||||
>
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
```dockerfile
|
||||
FROM alpine AS builder
|
||||
|
||||
RUN apk add git \
|
||||
&& git clone https://gitee.com/offends/Docs.git \
|
||||
&& tar -cvf Docker-Template.tar ./Docker-Template
|
||||
|
||||
FROM alpine AS builder-2
|
||||
|
||||
COPY --from=builder /Docker-Template.tar /
|
||||
RUN rm -rf /Docker-Template.tar
|
||||
|
||||
FROM alpine AS builder-3
|
||||
|
||||
COPY --from=builder /Docker-Template.tar /
|
||||
RUN tar -xvf /Docker-Template.tar
|
||||
```
|
||||
|
||||
开始构建
|
||||
|
||||
```bash
|
||||
docker build --target builder-3 -t app:v1 .
|
||||
```
|
||||
|
||||
## 替换构建镜像或参数
|
||||
|
||||
- 编写 Dockerfile
|
||||
|
||||
> Dockerfile 可定义变量在外部指定
|
||||
>
|
||||
|
||||
```bash
|
||||
vi Dockerfile
|
||||
```
|
||||
|
||||
```dockerfile
|
||||
# 默认镜像使用 alpine ,通过外部定义修改镜像为 ubuntu
|
||||
ARG IMAGE=alpine
|
||||
FROM ${IMAGE}
|
||||
|
||||
# 定义一个ENV,默认值为: default_env,外部传入 NAME_ARG 让 NAME 变量值改变为 demo_env
|
||||
ARG NAME_ARG
|
||||
ENV NAME=${NAME_ARG:-default_env}
|
||||
```
|
||||
|
||||
开始构建
|
||||
|
||||
```bash
|
||||
docker build --build-arg NAME_ARG=demo_env --build-arg IMAGE=ubuntu -t app:v1 .
|
||||
```
|
39
Docker/Docs/Docker部署Caddy.md
Normal file
39
Docker/Docs/Docker部署Caddy.md
Normal file
@@ -0,0 +1,39 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker部署Caddy
|
||||
|
||||
[官网](https://caddyserver.com/)
|
||||
|
||||
1. 启动 Caddy 容器
|
||||
|
||||
```bash
|
||||
docker run -itd \
|
||||
--restart always \
|
||||
-p 80:80 \
|
||||
-v /data/caddy:/etc/caddy/ \
|
||||
--name=caddy \
|
||||
caddy:latest
|
||||
```
|
||||
|
||||
2. 进入容器修改配置文件
|
||||
|
||||
```bash
|
||||
vi /data/caddy/Caddyfile
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
:80 {
|
||||
root * /etc/caddy/www
|
||||
file_server
|
||||
}
|
||||
```
|
||||
|
||||
3. 重启容器
|
||||
|
||||
```bash
|
||||
docker restart caddy
|
||||
```
|
||||
|
||||
4. 访问 IP:80
|
169
Docker/Docs/Docker部署Gitlab.md
Normal file
169
Docker/Docs/Docker部署Gitlab.md
Normal file
@@ -0,0 +1,169 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker部署Gitlab
|
||||
|
||||
[企业版官网网址](https://docs.gitlab.com/ee/install/docker.html)
|
||||
|
||||
> 部署开源版
|
||||
>
|
||||
> 例:本地 IP 为 192.168.1.10
|
||||
|
||||
## 部署Gitlab
|
||||
|
||||
1. 启动容器
|
||||
|
||||
> 这里也可以通过 `--hostname 192.168.1.10` 指定 Clone 地址,Gitlab会通过读取本地主机名作为默认的 Clone 地址
|
||||
|
||||
```bash
|
||||
docker run -itd \
|
||||
--restart always \
|
||||
-p 80:80 \
|
||||
-p 222:22 \
|
||||
-u root \
|
||||
-v $PWD/data/log:/var/log/gitlab \
|
||||
-v $PWD/data/opt:/var/opt/gitlab \
|
||||
-v $PWD/data/etc:/etc/gitlab \
|
||||
--privileged=true \
|
||||
--name=gitlab \
|
||||
gitlab/gitlab-ce:latest
|
||||
```
|
||||
|
||||
2. 进入容器查看 root 初始密码
|
||||
|
||||
```bash
|
||||
docker exec -it gitlab bash
|
||||
```
|
||||
|
||||
```bash
|
||||
cat /etc/gitlab/initial_root_password
|
||||
```
|
||||
|
||||
> 访问 192.168.1.10:80
|
||||
|
||||
3. 修改 SSH Clone 地址(进入容器内执行)
|
||||
|
||||
```bash
|
||||
cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak
|
||||
vi /etc/gitlab/gitlab.rb
|
||||
```
|
||||
|
||||
写入如下内容
|
||||
|
||||
```bash
|
||||
external_url "http://192.168.1.10:80" #http对外clone地址
|
||||
gitlab_rails["gitlab_ssh_host"] = "192.168.1.10" #ssh对外clone地址
|
||||
gitlab_rails["gitlab_shell_ssh_port"] = 222 #ssh对外clone端口
|
||||
```
|
||||
|
||||
4. 重启服务
|
||||
|
||||
```bash
|
||||
gitlab-ctl reconfigure
|
||||
```
|
||||
|
||||
## 安装Gitlab-runner
|
||||
|
||||
1. 启动容器
|
||||
|
||||
```bash
|
||||
docker run -itd --name gitlab-runner \
|
||||
--restart always \
|
||||
--privileged=true \
|
||||
-v $PWD/data/gitlab-runner-config:/etc/gitlab-runner \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /usr/local/bin/docker:/usr/bin/docker \
|
||||
gitlab/gitlab-runner:latest
|
||||
```
|
||||
|
||||
2. 创建 Runner 实例获取 Token
|
||||
|
||||
点击Admin Area(管理员设置) > 点击CI/CD > 点击Runners > 点击New project runner > 选择Linux > 填写一个Tags > 点击Create runner
|
||||
|
||||
3. 进入容器
|
||||
|
||||
```bash
|
||||
docker exec -it gitlab-runner bash
|
||||
```
|
||||
|
||||
4. 开始注册 Runner
|
||||
|
||||
```bash
|
||||
gitlab-ci-multi-runner register
|
||||
```
|
||||
|
||||
过程如下
|
||||
|
||||
```bash
|
||||
Runtime platform arch=amd64 os=linux pid=106 revision=6e766faf version=16.4.0
|
||||
Running in system-mode.
|
||||
|
||||
Enter the GitLab instance URL (for example, https://gitlab.com/):
|
||||
http://192.168.1.10 #Gitlab地址
|
||||
Enter the registration token:
|
||||
******** #刚刚获取到的Token
|
||||
Verifying runner... is valid runner=Te1gEas2d
|
||||
Enter a name for the runner. This is stored only in the local config.toml file:
|
||||
[f94c7a9b1272]: test #名称
|
||||
Enter an executor: docker+machine, instance, kubernetes, docker-windows, shell, virtualbox, docker-autoscaler, custom, docker, parallels, ssh:
|
||||
shell #输入一个执行器
|
||||
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
|
||||
|
||||
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
|
||||
```
|
||||
|
||||
5. 开始测试
|
||||
|
||||
在测试仓库内创建 `.gitlab-ci.yml` 文件编写内容
|
||||
|
||||
```yml
|
||||
stages:
|
||||
- test
|
||||
build-test:
|
||||
stage: test
|
||||
tags:
|
||||
- test
|
||||
script:
|
||||
- echo "Hello world"
|
||||
```
|
||||
|
||||
6. 查看结果
|
||||
|
||||
进入测试仓库 > 点击Build > 点击Pipelines > 查看到 `passed` 即为成功可点击进去查看
|
||||
|
||||
## 忘记密码
|
||||
|
||||
1. 进入容器
|
||||
|
||||
```bash
|
||||
docker exec -it gitlab /bin/bash
|
||||
```
|
||||
|
||||
2. 进⼊控制台(需要等待一段时间)
|
||||
|
||||
```bash
|
||||
gitlab-rails console -e production
|
||||
```
|
||||
|
||||
3. 查询root⽤户
|
||||
|
||||
```bash
|
||||
user=User.where(id:1).first
|
||||
```
|
||||
|
||||
4. 设置密码
|
||||
|
||||
```bash
|
||||
user.password='password'
|
||||
```
|
||||
|
||||
5. 保存退出
|
||||
|
||||
```bash
|
||||
user.save!
|
||||
exit
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
31
Docker/Docs/Docker部署JumpServer.md
Normal file
31
Docker/Docs/Docker部署JumpServer.md
Normal file
@@ -0,0 +1,31 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker部署JumpServer
|
||||
|
||||
[官网](https://docs.jumpserver.org/zh/master/install/setup_by_fast/) [JumpServer安装包](https://github.com/jumpserver/installer/releases)
|
||||
|
||||
1. 部署 Mysql 数据库
|
||||
|
||||
```bash
|
||||
docker run -itd --name jump-mysql \
|
||||
--restart=always -p 3306:3306 \
|
||||
-v /usr/local/jumpserver/data:/var/lib/mysql \
|
||||
-v /usr/local/jumpserver/logs:/var/log/mysql \
|
||||
-v /usr/local/jumpserver/conf:/etc/mysql/conf.d \
|
||||
-e MYSQL_ROOT_PASSWORD=jumpserver \
|
||||
-e MYSQL_DATABASE=jumpserver \
|
||||
mysql:5.7
|
||||
```
|
||||
|
||||
2. 解压 JumpServer 安装包
|
||||
|
||||
```bash
|
||||
tar -xf jumpserver-installer-v*.tar.gz
|
||||
cd jumpserver-installer-v*
|
||||
```
|
||||
|
||||
3. 修改 `config-example.txt` 文件配置参数, 并启动
|
||||
|
||||
```bash
|
||||
./jmsctl.sh install
|
||||
```
|
58
Docker/Docs/Docker部署Nacos.md
Normal file
58
Docker/Docs/Docker部署Nacos.md
Normal file
@@ -0,0 +1,58 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker部署Nacos
|
||||
|
||||
[官网文档](https://nacos.io/zh-cn/docs/v2/guide/user/auth.html)
|
||||
|
||||
1. 启动 MYSQL
|
||||
|
||||
```bash
|
||||
docker run --name nacos-mysql --restart=always \
|
||||
-p 3306:3306 \
|
||||
-v /data/mysql:/var/lib/mysql \
|
||||
-e MYSQL_USER=nacos \
|
||||
-e MYSQL_PASSWORD=nacos \
|
||||
-e MYSQL_DATABASE=nacos \
|
||||
-e MYSQL_ROOT_PASSWORD=root \
|
||||
-d mysql:latest
|
||||
```
|
||||
|
||||
2. 启动 NACOS
|
||||
|
||||
```bash
|
||||
docker run --name nacos --restart=always \
|
||||
-p 8848:8848 \
|
||||
-e MYSQL_SERVICE_HOST=${MYSQL_HOST} \
|
||||
-e MYSQL_SERVICE_PORT=3306 \
|
||||
-e MYSQL_SERVICE_USER=nacos \
|
||||
-e MYSQL_SERVICE_PASSWORD=nacos \
|
||||
-e MYSQL_SERVICE_DB_NAME=nacos \
|
||||
-e MODE=standalone \
|
||||
-e PREFER_HOST_MODE=hostname \
|
||||
-d mysql:latest
|
||||
```
|
||||
|
||||
3. 开启登录
|
||||
|
||||
```bash
|
||||
vi /data/nacos/application.properties
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
# vi /data/nacos/application.properties
|
||||
nacos.core.auth.enabled=true
|
||||
nacos.core.auth.server.identity.key=nacos
|
||||
nacos.core.auth.server.identity.value=nacos
|
||||
|
||||
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
|
||||
```
|
||||
|
||||
4. 访问:http://localhost:8848/nacos/#/login
|
||||
|
||||
> 启动挂载配置文件
|
||||
>
|
||||
> ```bash
|
||||
> -e /data/nacos/application.properties:/home/nacos/conf/application.properties
|
||||
> ```
|
16
Docker/Docs/Docker部署Node-exporter.md
Normal file
16
Docker/Docs/Docker部署Node-exporter.md
Normal file
@@ -0,0 +1,16 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker部署Node-exporter
|
||||
|
||||
```bash
|
||||
docker run -d --restart=always \
|
||||
-p 9100:9100 \
|
||||
-v "/proc:/host/proc:ro" \
|
||||
-v "/sys:/host/sys:ro" \
|
||||
-v "/:/rootfs:ro" \
|
||||
--net="host" \
|
||||
--restart=always \
|
||||
--name node-exporter \
|
||||
prom/node-exporter
|
||||
```
|
||||
|
45
Docker/Docs/Docker部署Portainer.md
Normal file
45
Docker/Docs/Docker部署Portainer.md
Normal file
@@ -0,0 +1,45 @@
|
||||
> 本文作者:丁辉
|
||||
>
|
||||
|
||||
# Docker部署Portainer
|
||||
|
||||
[官方文档](https://docs.portainer.io/)
|
||||
|
||||
> 通过Portainer管理docker
|
||||
|
||||
## Docker部署
|
||||
|
||||
```bash
|
||||
docker run -d -p 9000:9000 \
|
||||
--name portainer --restart=always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /data/portainer:/data \
|
||||
portainer/portainer-ce:latest
|
||||
```
|
||||
|
||||
## 远程连接Docker
|
||||
|
||||
远程连接默认端口是2375 [Docker配置2375端口文档](https://gitee.com/offends/Kubernetes/blob/main/Docker/Docs/Docker%E9%85%8D%E7%BD%AE2375%E7%AB%AF%E5%8F%A3.md)
|
||||
|
||||
## 忘记密码
|
||||
|
||||
1. 下载新镜像
|
||||
|
||||
```bash
|
||||
docker pull portainer/helper-reset-password
|
||||
```
|
||||
|
||||
2. 关闭容器
|
||||
|
||||
```bash
|
||||
docker stop portainer
|
||||
```
|
||||
|
||||
3. 启动观看密码
|
||||
|
||||
```bash
|
||||
docker run --rm -v portainer_data:/data portainer/helper-reset-password
|
||||
```
|
||||
|
||||
|
||||
|
158
Docker/Docs/Docker部署Watchtower管理容器更新.md
Normal file
158
Docker/Docs/Docker部署Watchtower管理容器更新.md
Normal file
@@ -0,0 +1,158 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker部署Watchtower管理容器更新
|
||||
|
||||
[Github仓库](https://github.com/containrrr/watchtower)
|
||||
|
||||
## 介绍
|
||||
|
||||
Watchtower 是一个开源的容器监控和自动更新工具,设计用于Docker容器环境。它可以监控正在运行的容器及其使用的镜像,当发现镜像有更新时,自动拉取新镜像并重新启动容器。这种自动化管理方式有助于确保部署的应用保持最新状态,从而减少安全风险和改进功能。
|
||||
|
||||
## 快速开始
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower
|
||||
```
|
||||
|
||||
所有容器都会自动更新,也包括 Watchtower 本身。
|
||||
|
||||
## 其他启动参数
|
||||
|
||||
- 自动清除旧镜像
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower \
|
||||
--cleanup
|
||||
```
|
||||
|
||||
> `--cleanup` 选项可以简写为 `-c`
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c
|
||||
```
|
||||
|
||||
- 选择性自动更新
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c \
|
||||
nginx redis
|
||||
```
|
||||
|
||||
- 配置容器更新列表
|
||||
|
||||
```bash
|
||||
vi ~/.watchtower.list
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
nginx
|
||||
reidis
|
||||
```
|
||||
|
||||
启动 Watchtower 容器
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c \
|
||||
$(cat ~/.watchtower.list)
|
||||
```
|
||||
|
||||
- 设置单个容器自动更新标签
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name nginx \
|
||||
--restart always \
|
||||
--label com.centurylinklabs.watchtower.enable=true \
|
||||
nginx:latest
|
||||
```
|
||||
|
||||
启动 Watchtower 容器
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c \
|
||||
--label-enable
|
||||
```
|
||||
|
||||
> `--label-enable` 可以简写为 `-e`
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -ce
|
||||
```
|
||||
|
||||
- 设置自动更新检查频率
|
||||
|
||||
- `--interval` 设置更新检测时间间隔单位为秒。
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c \
|
||||
--interval 3600
|
||||
```
|
||||
|
||||
- `--schedule` 设置定时检测更新时间。格式为 6 字段 Cron 表达式,而非传统的 5 字段,第一位是秒。
|
||||
|
||||
> 比如每天凌晨 2 点检查一次更新
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c \
|
||||
--schedule "0 0 2 * * *"
|
||||
```
|
||||
|
||||
- 手动更新
|
||||
|
||||
> 检查 nginx 是否需要更新
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -c \
|
||||
--run-once \
|
||||
nginx
|
||||
```
|
||||
|
||||
> `--run-once` 可以简写为 `-R`
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower -cR \
|
||||
nginx
|
||||
```
|
||||
|
||||
> 当容器设置过 `com.centurylinklabs.watchtower.enable=false` 参数则不会更新
|
63
Docker/Docs/Docker配合Mysql-Secrets使用.md
Normal file
63
Docker/Docs/Docker配合Mysql-Secrets使用.md
Normal file
@@ -0,0 +1,63 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker配合Mysql-Secrets使用
|
||||
|
||||
1. 配置密码
|
||||
|
||||
```bash
|
||||
echo "root" > root-pass.txt
|
||||
echo "root" > offends-pass.txt
|
||||
```
|
||||
|
||||
2. 创建 Secrets
|
||||
|
||||
```bash
|
||||
docker secret create mysql-root-pass ./root-pass.txt
|
||||
docker secret create mysql-offends-pass ./offends-pass.txt
|
||||
```
|
||||
|
||||
3. 构建容器
|
||||
|
||||
```bash
|
||||
docker build -t mysql:v1 --file=./Dockerfile-secrets .
|
||||
```
|
||||
|
||||
4. 创建持久化目录
|
||||
|
||||
```bash
|
||||
mkdir /data/mysqld
|
||||
```
|
||||
|
||||
5. 启动容器
|
||||
|
||||
```bash
|
||||
docker service create \
|
||||
--name mysql \
|
||||
--replicas 1 \
|
||||
--publish published=3306,target=3306 \
|
||||
--mount type=bind,source=/data/mysqld,destination=/var/lib/mysql \
|
||||
--secret source=mysql-root-pass,target=/run/secrets/mysql-root-pass \
|
||||
--secret source=mysql-offends-pass,target=/run/secrets/mysql-offends-pass \
|
||||
mysql:v1
|
||||
```
|
||||
|
||||
6. 查看
|
||||
|
||||
```bash
|
||||
docker service ps mysql
|
||||
```
|
||||
|
||||
> 查看完整事件
|
||||
>
|
||||
> ```bash
|
||||
> docker service ps mysql --no-trunc
|
||||
> ```
|
||||
|
||||
7. 停止容器
|
||||
|
||||
```bash
|
||||
docker service rm mysql
|
||||
```
|
||||
|
||||
|
||||
|
165
Docker/Docs/Docker配置2375端口.md
Normal file
165
Docker/Docs/Docker配置2375端口.md
Normal file
@@ -0,0 +1,165 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker配置2375端口
|
||||
|
||||
## 方法一
|
||||
|
||||
1. 配置 `/etc/docker/daemon.json` 文件
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```json
|
||||
{
|
||||
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
|
||||
}
|
||||
```
|
||||
|
||||
2. 重载并重启 Docker
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
## 方法二
|
||||
|
||||
1. 修改 `/usr/lib/systemd/system/docker.service` 文件
|
||||
|
||||
```bash
|
||||
vi /usr/lib/systemd/system/docker.service
|
||||
```
|
||||
|
||||
- 旧版 Docker
|
||||
|
||||
```bash
|
||||
ExecStart=/usr/local/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
|
||||
```
|
||||
|
||||
- 新版 Docker
|
||||
|
||||
```bash
|
||||
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
|
||||
```
|
||||
|
||||
2. 重载并重启 Docker
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
## 验证
|
||||
|
||||
- 查看端口是否启动
|
||||
|
||||
```bash
|
||||
netstat -anput | grep 2375
|
||||
```
|
||||
|
||||
- 测试
|
||||
|
||||
```bash
|
||||
docker -H tcp://192.168.1.10:2375 ps
|
||||
```
|
||||
|
||||
# 配置证书访问
|
||||
|
||||
1. 可以使用本脚本生成证书
|
||||
|
||||
```bash
|
||||
curl -Os https://gitee.com/offends/Linux/raw/main/File/Shell/openssl-cert.sh && chmod 777 ./openssl-cert.sh
|
||||
```
|
||||
|
||||
> 修改
|
||||
>
|
||||
> ```bash
|
||||
> IP="127.0.0.1" # 本地 IP 地址
|
||||
> PASSWORD="123456" # 证书密码
|
||||
> VALIDITY_PERIOD=3650 # 证书有效时间
|
||||
> ```
|
||||
|
||||
2. 执行脚本
|
||||
|
||||
```bash
|
||||
./openssl-cert.sh
|
||||
```
|
||||
|
||||
3. 修改 `/usr/lib/systemd/system/docker.service` 文件
|
||||
|
||||
```bash
|
||||
vi /usr/lib/systemd/system/docker.service
|
||||
```
|
||||
|
||||
- 旧版 Docker
|
||||
|
||||
```bash
|
||||
ExecStart=/usr/bin/dockerd --tlsverify --tlscacert=/etc/docker/cert/2375/ca.pem --tlscert=/etc/docker/cert/2375/server-cert.pem --tlskey=/etc/docker/cert/2375/server-key.pem -H unix:///var/run/docker.sock
|
||||
```
|
||||
|
||||
- 新版 Docker
|
||||
|
||||
```bash
|
||||
ExecStart=/usr/bin/dockerd --tlsverify --tlscacert=/etc/docker/cert/2375/ca.pem --tlscert=/etc/docker/cert/2375/server-cert.pem --tlskey=/etc/docker/cert/2375/server-key.pem -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
|
||||
```
|
||||
|
||||
4. 重载并重启 Docker
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
5. 验证
|
||||
|
||||
```bash
|
||||
docker --tlsverify --tlscacert=/etc/docker/cert/2375/ca.pem --tlscert=/etc/docker/cert/2375/server-cert.pem --tlskey=/etc/docker/cert/2375/server-key.pem -H tcp://192.168.1.10:2375 ps
|
||||
```
|
||||
|
||||
# 问题记录
|
||||
|
||||
> [方法一] 由于 Docker 在最近新版更换了容器引擎为 Containerd, daemon.json 文件如果配置原来的通信套接字文件路径是不行的,现在也没有更好的解决方案,本次我就记录一下从老外那里学来的方法。
|
||||
>
|
||||
> 嗯......为什么说这个方案也不是很对呢,因为他会替换你的 Docker 启动命令,那为什么不直接改 `docker.service` 呢?反正咱只是记录一下,通过修改 docker.service 方法我也放在 [方法二] 里了你们自己看吧
|
||||
|
||||
1. 配置 `/etc/docker/daemon.json` 文件
|
||||
|
||||
```bash
|
||||
vi /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```json
|
||||
{
|
||||
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
|
||||
}
|
||||
```
|
||||
|
||||
2. 创建 `override.conf` 文件
|
||||
|
||||
```bash
|
||||
mkdir -p /etc/systemd/system/docker.service.d/
|
||||
vi /etc/systemd/system/docker.service.d/override.conf
|
||||
```
|
||||
|
||||
文件内容为
|
||||
|
||||
```bash
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=/usr/bin/dockerd --config-file /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
3. 重载并重启 Docker
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
|
||||
|
83
Docker/Docs/Docker配置代理.md
Normal file
83
Docker/Docs/Docker配置代理.md
Normal file
@@ -0,0 +1,83 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker配置代理
|
||||
|
||||
## Docker服务代理配置
|
||||
|
||||
> 此方法适用于 `docker pull` 镜像配置代理
|
||||
|
||||
创建 Systemd 代理文件
|
||||
|
||||
```bash
|
||||
mkdir -p /etc/systemd/system/docker.service.d
|
||||
touch /etc/systemd/system/docker.service.d/proxy.conf
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
[Service]
|
||||
Environment="HTTP_PROXY=http://127.0.0.1:15777"
|
||||
Environment="HTTPS_PROXY=http://127.0.0.1:15777"
|
||||
Environment="NO_PROXY=localhost,127.0.0.1,example.com"
|
||||
```
|
||||
|
||||
- `HTTP_PROXY=`:设置HTTP代理服务器
|
||||
- `HTTPS_PROXY=`:设置HTTPS代理服务器
|
||||
- `NO_PROXY=""`:设置不使用代理服务器的域名或IP地址列表
|
||||
|
||||
> 将 `http://127.0.0.1:15777` 换成可用的代理即可
|
||||
|
||||
重启生效
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
## 容器内部代理
|
||||
|
||||
> 在容器运行阶段,如果需要代理上网,则需要配置 `~/.docker/config.json`。
|
||||
|
||||
创建 Config.json 代理文件
|
||||
|
||||
```bash
|
||||
mkdir ~/.docker/
|
||||
vi ~/.docker/config.json
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```json
|
||||
{
|
||||
"proxies":
|
||||
{
|
||||
"default":
|
||||
{
|
||||
"httpProxy": "http://192.168.1.100:15777",
|
||||
"httpsProxy": "http://192.168.1.100:15777",
|
||||
"noProxy": "localhost,127.0.0.1,example.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> 此外, 也可以直接在容器运行时通过注入 `http_proxy` 等环境变量进行代理
|
||||
|
||||
重启生效
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
```
|
||||
|
||||
## DockerBuild代理
|
||||
|
||||
```bash
|
||||
docker build . \
|
||||
--build-arg "HTTP_PROXY=http://192.168.1.100:15777" \
|
||||
--build-arg "HTTPS_PROXY=http://192.168.1.100:15777" \
|
||||
--build-arg "NO_PROXY=localhost,127.0.0.1,example.com" \
|
||||
-t your/image:tag
|
||||
```
|
||||
|
137
Docker/Docs/Docker配置守护进程.md
Normal file
137
Docker/Docs/Docker配置守护进程.md
Normal file
@@ -0,0 +1,137 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker配置守护进程
|
||||
|
||||
> 通过修改 `/etc/docker/daemon.json` 配置守护进程
|
||||
>
|
||||
> [官方文档](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon) [示例文件位置](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file)
|
||||
|
||||
- 编写基础配置
|
||||
|
||||
```json
|
||||
{
|
||||
"registry-mirrors": [
|
||||
"https://dockerhub.azk8s.cn",
|
||||
"https://docker.mirrors.ustc.edu.cn",
|
||||
"http://hub-mirror.c.163.com"
|
||||
],
|
||||
"insecure-registries": [],
|
||||
"max-concurrent-downloads": 10,
|
||||
"max-concurrent-uploads": 10,
|
||||
"log-driver": "json-file",
|
||||
"log-level": "warn",
|
||||
"log-opts": {
|
||||
"max-size": "10m",
|
||||
"max-file": "3"
|
||||
},
|
||||
"data-root": "/var/lib/docker"
|
||||
}
|
||||
```
|
||||
|
||||
- 建立垃圾收集
|
||||
|
||||
```json
|
||||
{
|
||||
"builder": {
|
||||
"gc": {
|
||||
"enabled": true,
|
||||
"defaultKeepStorage": "10GB",
|
||||
"policy": [
|
||||
{ "keepStorage": "10GB", "filter": ["unused-for=2200h"] },
|
||||
{ "keepStorage": "50GB", "filter": ["unused-for=3300h"] },
|
||||
{ "keepStorage": "100GB", "all": true }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- 验证守护进程配置文件
|
||||
|
||||
```bash
|
||||
dockerd --validate --config-file=/etc/docker/daemon.json
|
||||
```
|
||||
|
||||
- 重载 Docker
|
||||
|
||||
```bash
|
||||
systemctl reload docker
|
||||
```
|
||||
|
||||
|
||||
|
||||
# 参数
|
||||
|
||||
| 参数 | 用法和说明 | 默认值/示例 |
|
||||
| -------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| allow-nondistributable-artifacts | 允许的非分发性文件列表(为空) | true/false |
|
||||
| api-cors-header | API的跨源资源共享(CORS)头部,允许对API进行跨域请求 | "" (空字符串)或 * 或指定IP地址或域名 |
|
||||
| authorization-plugins | 授权插件列表(为空) | |
|
||||
| bip | 容器网络的默认桥接接口的IP范围 | "" (空字符串) |
|
||||
| bridge | 指定容器网络的默认桥接接口 | "" (空字符串) |
|
||||
| cgroup-parent | 指定容器的cgroup父目录 | |
|
||||
| containerd | 容器运行时 containerd 的socket路径 | "/run/containerd/containerd.sock" |
|
||||
| containerd-namespace | 容器运行时 containerd 的命名空间 | "docker" |
|
||||
| containerd-plugin-namespace | 容器运行时 containerd 插件的命名空间 | "docker-plugins" |
|
||||
| data-root | Docker 数据的根目录路径 | |
|
||||
| debug | 是否启用调试模式 | true/false(根据具体实现或配置文件而定) |
|
||||
| default-address-pools | 默认的地址池设置列表,包括基础地址和子网大小 | 示例:[](空列表) |
|
||||
| default-cgroupns-mode | 默认的cgroup命名空间模式(通常是私有) | "private"(私有模式) |
|
||||
| default-gateway | 默认网关设置 | |
|
||||
| default-gateway-v6 | 默认IPv6网关设置 | |
|
||||
| default-network-opts | 默认网络选项 | |
|
||||
| default-runtime | 默认容器运行时 | "runc"(具体容器运行时的名称) |
|
||||
| default-shm-size | 默认的共享内存大小 | "64M"(64兆字节) |
|
||||
| default-ulimits | 默认的ulimit设置,指定文件描述符的硬限制和软限制 | 示例:{"nofile": {"Hard": 64000, "Name": "nofile", "Soft": 64000}} (文件描述符限制示例) |
|
||||
| dns | DNS服务器列表 | 示例:[](空列表) |
|
||||
| dns-opts | DNS选项列表 | 示例:[](空列表) |
|
||||
| dns-search | DNS搜索域列表 | 示例:[](空列表) |
|
||||
| exec-opts | 容器执行参数列表 | 示例:[](空列表) |
|
||||
| exec-root | 容器执行的根目录路径 | "" (空字符串) |
|
||||
| experimental | 是否启用实验性功能 | true/false(根据具体实现或配置文件而定) |
|
||||
| features | Docker功能列表 | |
|
||||
| fixed-cidr | 固定CIDR地址设置(通常用于设置 Docker 容器的 IP 地址) | "" (空字符串) |
|
||||
| fixed-cidr-v6 | 固定IPv6 CIDR地址设置(通常用于设置 Docker 容器的 IPv6 地址) | "" (空字符串) |
|
||||
| group | Docker进程的用户组 | |
|
||||
| hosts | 主机名设置列表 | 示例:[](空列表) |
|
||||
| proxies | 代理设置,包括HTTP代理、HTTPS代理和不使用代理的地址列表 | |
|
||||
| icc | 是否启用容器间通信 | false (默认值为false) |
|
||||
| init | 是否启用自定义初始化进程 | false (默认值为false) |
|
||||
| init-path | 自定义初始化进程的路径 | "/usr/libexec/docker-init" |
|
||||
| insecure-registries | 不安全的镜像仓库列表 | 示例:[](空列表) |
|
||||
| ip | Docker守护进程监听的IP地址 | 0.0.0.0 |
|
||||
| ip-forward | 是否启用IP转发 | false (默认值为false) |
|
||||
| ip-masq | 是否启用IP伪装 | false (默认值为false) |
|
||||
| iptables | 是否启用iptables | false (默认值为false) |
|
||||
| ip6tables | 是否启用ip6tables | false (默认值为false) |
|
||||
| ipv6 | 是否启用IPv6 | true/false(根据具体实现或配置文件而定) |
|
||||
| labels | 标签设置列表 | 示例:[](空列表) |
|
||||
| live-restore | 是否启用容器守护进程在宕机时自动恢复容器 | true/false(根据具体实现或配置文件而定) |
|
||||
| log-driver | 日志驱动设置(默认为json-file) | "json-file"(JSON文件) |
|
||||
| log-level | 日志级别设置 | "" (空字符串) |
|
||||
| log-opts | 日志选项设置,包括缓存禁用、缓存大小、缓存最大文件数等 | 示例:{"max-size": "10m", "max-file": "5"}(最大大小为10兆字节,最大文件数为5) |
|
||||
| max-concurrent-downloads | 最大并发下载任务数 | 3(示例值) |
|
||||
| max-concurrent-uploads | 最大并发上传任务数 | 5(示例值) |
|
||||
| max-download-attempts | 最大下载尝试次数 | 5(示例值) |
|
||||
| mtu | 最大传输单元设置 | 0(示例值) |
|
||||
| no-new-privileges | 是否禁用新特权 | false (默认值为false) |
|
||||
| node-generic-resources | 节点通用资源列表,通常用于指定GPU等硬件资源 | 示例:["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"](GPU资源示例) |
|
||||
| oom-score-adjust | OOM分数调整设置 | 0(示例值) |
|
||||
| pidfile | PID文件路径设置 | |
|
||||
| raw-logs | 是否启用原始日志记录 | true/false(根据具体实现或配置文件而定) |
|
||||
| registry-mirrors | 镜像仓库镜像设置列表 | 示例:[](空列表) |
|
||||
| runtimes | 容器运行时设置,可以包括自定义运行时的路径和参数 | |
|
||||
| seccomp-profile | 安全策略配置文件路径 | "" (空字符串) |
|
||||
| selinux-enabled | 是否启用SELinux | true/false(根据具体实现或配置文件而定) |
|
||||
| shutdown-timeout | 容器守护进程关闭超时设置 | 15(示例值) |
|
||||
| storage-driver | 存储驱动设置 | |
|
||||
| storage-opts | 存储选项设置列表 | 示例:[](空列表) |
|
||||
| swarm-default-advertise-addr | Swarm模式下的默认广告地址设置 | |
|
||||
| tls | 是否启用TLS | true/false(根据具体实现或配置文件而定) |
|
||||
| tlscacert | TLS CA证书路径 | |
|
||||
| tlscert | TLS证书路径 | |
|
||||
| tlskey | TLS密钥路径 | |
|
||||
| tlsverify | 是否验证TLS | true/false(根据具体实现或配置文件而定) |
|
||||
| userland-proxy | 是否使用用户空间代理 | true/false(根据具体实现或配置文件而定) |
|
||||
| userland-proxy-path | 用户空间代理的路径 | "/usr/libexec/docker-proxy" |
|
||||
| userns-remap | 用户命名空间重映射设置 | |
|
27
Docker/Docs/Docker镜像批量打包.md
Normal file
27
Docker/Docs/Docker镜像批量打包.md
Normal file
@@ -0,0 +1,27 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker镜像批量打包
|
||||
|
||||
- 第一种
|
||||
|
||||
```bash
|
||||
docker save $(docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o k8s-master.tar
|
||||
```
|
||||
|
||||
- 第二种
|
||||
|
||||
> 将需要统一打包的镜像写在文件内
|
||||
|
||||
```bash
|
||||
cat > images.txt <<EOF
|
||||
nginx:alpine
|
||||
nginx:latest
|
||||
EOF
|
||||
```
|
||||
|
||||
打包
|
||||
|
||||
```bash
|
||||
docker save -o images.tar.gz $(cat images.txt)
|
||||
```
|
||||
|
234
Docker/Docs/Docker集群.md
Normal file
234
Docker/Docs/Docker集群.md
Normal file
@@ -0,0 +1,234 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker Swarm集群
|
||||
|
||||
[官方文档](https://docs.docker.com/engine/swarm/swarm-tutorial/deploy-service/)
|
||||
|
||||
| 节点IP | 角色 |
|
||||
| :----------: | :----: |
|
||||
| 192.168.1.10 | MASTER |
|
||||
| 192.168.1.20 | WORKER |
|
||||
|
||||
## 开始组建集群
|
||||
|
||||
1. 初始化 MASTER 节点
|
||||
|
||||
```bash
|
||||
docker swarm init
|
||||
```
|
||||
|
||||
> 指定 IP
|
||||
>
|
||||
> ```bash
|
||||
> docker swarm init --advertise-addr 192.168.1.10
|
||||
> ```
|
||||
>
|
||||
> 指定网段
|
||||
>
|
||||
> ```bash
|
||||
> --default-addr-pool 192.168.1.0/24
|
||||
> ```
|
||||
|
||||
2. WORKER 节点加入集群
|
||||
|
||||
```bash
|
||||
docker swarm join --token <token> 192.168.1.10:2377
|
||||
```
|
||||
|
||||
3. 检查所有节点
|
||||
|
||||
```bash
|
||||
docker node ls
|
||||
```
|
||||
|
||||
> 删除节点命令为
|
||||
>
|
||||
> ```bash
|
||||
> docker swarm leave
|
||||
> ```
|
||||
>
|
||||
> 强制使用 ` --force` 参数
|
||||
|
||||
## 常用基础命令
|
||||
|
||||
- 查看加入 MASTER TOKEN
|
||||
|
||||
```bash
|
||||
docker swarm join-token manager
|
||||
```
|
||||
|
||||
- 查看加入 WORKER TOKEN
|
||||
|
||||
```bash
|
||||
docker swarm join-token worker
|
||||
```
|
||||
|
||||
- 查看所有节点
|
||||
|
||||
```bash
|
||||
docker node ls
|
||||
```
|
||||
|
||||
- 查看节点详情
|
||||
|
||||
```bash
|
||||
docker node inspect <节点名称> --pretty
|
||||
```
|
||||
|
||||
|
||||
## Secrets 基础操作
|
||||
|
||||
- 创建 Secrets
|
||||
|
||||
```
|
||||
docker secret create <Secrets名称> ./<文件位置>
|
||||
```
|
||||
|
||||
> echo 创建 Secrets
|
||||
>
|
||||
> ```bash
|
||||
> echo "内容" | docker secret create <Secrets名称> -
|
||||
> ```
|
||||
>
|
||||
> openssl 创建 Secrets,生成一个随机的20个字符的密码,并将其作为密钥存储到Docker中
|
||||
>
|
||||
> ```bash
|
||||
> openssl rand -base64 20 | docker secret create mysql_password -
|
||||
> ```
|
||||
|
||||
- 查看 Secrets
|
||||
|
||||
```bash
|
||||
docker secret ls
|
||||
```
|
||||
|
||||
- 检查 Secrets
|
||||
|
||||
```bash
|
||||
docker secret inspect <Secrets名称>
|
||||
```
|
||||
|
||||
- 删除 Secrets
|
||||
|
||||
```bash
|
||||
docker secret rm <Secrets名称>
|
||||
```
|
||||
|
||||
## Network 基础操作
|
||||
|
||||
- 创建 Network
|
||||
|
||||
```
|
||||
docker network create -d overlay <网络名称>
|
||||
```
|
||||
|
||||
- 查看 Network
|
||||
|
||||
```bash
|
||||
docker network ls
|
||||
```
|
||||
|
||||
- 检查 Network
|
||||
|
||||
```bash
|
||||
docker network inspect <网络名称>
|
||||
```
|
||||
|
||||
- 删除 Network
|
||||
|
||||
```bash
|
||||
docker network rm <网络名称>
|
||||
```
|
||||
|
||||
## Volume 基础操作
|
||||
|
||||
- 创建 Volume
|
||||
|
||||
```
|
||||
docker volume create -d overlay <存储名称>
|
||||
```
|
||||
|
||||
- 查看 Volume
|
||||
|
||||
```bash
|
||||
docker volume ls
|
||||
```
|
||||
|
||||
- 检查 Volume
|
||||
|
||||
```bash
|
||||
docker volume inspect <存储名称>
|
||||
```
|
||||
|
||||
- 删除 Volume
|
||||
|
||||
```bash
|
||||
docker volume rm <存储名称>
|
||||
```
|
||||
|
||||
## 启动容器测试
|
||||
|
||||
```bash
|
||||
docker service create \
|
||||
--name mysql \
|
||||
--replicas 1 \
|
||||
--mount type=bind,source=/data/mysqld,destination=/var/lib/mysql \
|
||||
-e MYSQL_ROOT_PASSWORD="root" \
|
||||
mysql
|
||||
```
|
||||
|
||||
**其他参数**
|
||||
|
||||
- 指定 Docker 节点
|
||||
|
||||
```bash
|
||||
--constraint 'node.hostname==节点名称'
|
||||
```
|
||||
|
||||
- 指定对外端口
|
||||
|
||||
```bash
|
||||
--publish published=<容器对外端口>,target=<容器内部端口>
|
||||
```
|
||||
|
||||
- 挂载 volume 存储
|
||||
|
||||
```bash
|
||||
--mount type=volume,source=<指定存储名称>,destination=<容器内部路径>
|
||||
```
|
||||
|
||||
- 指定网络
|
||||
|
||||
```bash
|
||||
--network <网络名称>
|
||||
```
|
||||
|
||||
- 挂载 secret
|
||||
|
||||
```bash
|
||||
--secret source=<secret名称>,target=<容器内路径>
|
||||
```
|
||||
|
||||
|
||||
**常见参数说明**
|
||||
|
||||
| 参数 | 说明 |
|
||||
| :--------------------------: | :-----------------------------------: |
|
||||
| `--name` | 指定服务的名称 |
|
||||
| `--replicas` | 指定服务的副本数 |
|
||||
| `--constraint` | 指定服务运行的节点约束条件 |
|
||||
| `--publish` | 将容器的端口映射到主机的端口 |
|
||||
| `--mount` | 将主机上的目录或文件挂载到容器内 |
|
||||
| `--network` | 将服务连接到指定的Docker网络 |
|
||||
| `--secret` | 将指定的Docker secret文件挂载到容器内 |
|
||||
| `-e` | 指定容器内的环境变量 |
|
||||
| `--env-file` | 指定容器内的环境变量文件 |
|
||||
| `--restart-condition` | 指定容器的重启策略 |
|
||||
| `--update-delay` | 指定服务更新之间的延迟时间 |
|
||||
| `--update-parallelism` | 指定服务更新时的并行数量 |
|
||||
| `--update-failure-action` | 指定服务更新失败后的操作 |
|
||||
| `--update-max-failure-ratio` | 指定服务更新失败的最大比率 |
|
||||
| `--endpoint-mode` | 指定服务的网络端点模式 |
|
||||
|
||||
|
||||
|
41
Docker/Docs/Mysql容器纳入System管理.md
Normal file
41
Docker/Docs/Mysql容器纳入System管理.md
Normal file
@@ -0,0 +1,41 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Mysql容器纳入System管理
|
||||
|
||||
1. 创建 Systemd Service 文件
|
||||
|
||||
```bash
|
||||
vi /usr/lib/systemd/system/mysql.service
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```bash
|
||||
[Unit]
|
||||
Description=Mysql container
|
||||
Requires=docker.service
|
||||
After=docker.service
|
||||
[Service]
|
||||
RemainAfterExit=yes
|
||||
ExecStop=/usr/bin/docker stop mysql # 容器名
|
||||
ExecStart=/usr/bin/docker start mysql
|
||||
ExecReload=/usr/bin/docker restart mysql
|
||||
Restart=on-abnormal
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
2. 重载配置文件
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
```
|
||||
|
||||
3. 启动 Mysql
|
||||
|
||||
```bash
|
||||
systemctl start mysql
|
||||
```
|
||||
|
||||
|
||||
|
57
Docker/Docs/Nginx配置文件读取变量.md
Normal file
57
Docker/Docs/Nginx配置文件读取变量.md
Normal file
@@ -0,0 +1,57 @@
|
||||
> 本文作者:丁辉
|
||||
>
|
||||
|
||||
# Nginx配置文件读取变量
|
||||
|
||||
## 方法一使用 Envsubst 渲染替换环境变量
|
||||
|
||||
1. 编辑 Dockerfile
|
||||
|
||||
```dockerfile
|
||||
FROM nginx:alpine-slim
|
||||
|
||||
COPY ./nginx.conf.template /etc/nginx/conf.d/nginx.conf.template
|
||||
|
||||
ENV PROXY_SERVER=default
|
||||
|
||||
CMD /bin/sh -c "envsubst '\$PROXY_SERVER \$SERVER_NAME' < /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
|
||||
```
|
||||
|
||||
2. 编辑 nginx.conf.template 文件
|
||||
|
||||
```bash
|
||||
vi nginx.conf.template
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${SERVER_NAME};
|
||||
|
||||
location / {
|
||||
proxy_pass http://${PROXY_SERVER}:3080;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. 构建镜像
|
||||
|
||||
```bash
|
||||
docker build -t <name:tag> .
|
||||
```
|
||||
|
||||
4. 启动容器(指定变量)
|
||||
|
||||
```bash
|
||||
docker run -itd -e PROXY_SERVER=127.0.0.1 -e SERVER_NAME=localhost <name:tag>
|
||||
```
|
||||
|
||||
## 方法二
|
||||
|
||||
**查看此文档**
|
||||
|
||||
[Nginx镜像构建](https://gitee.com/offends/Kubernetes/tree/main/Docker/Dockerfile/Nginx)
|
43
Docker/Docs/OpeneUleros部署Docker.md
Normal file
43
Docker/Docs/OpeneUleros部署Docker.md
Normal file
@@ -0,0 +1,43 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# OpeneUleros部署Docker
|
||||
|
||||
> OpeneUleros 为 dnf 包管理工具, 所以特意记录本次安装
|
||||
|
||||
## 基础配置
|
||||
|
||||
1. 修改chrony时间同步配置
|
||||
|
||||
```bash
|
||||
sed -i 's/pool pool.ntp.org iburst/pool ntp.aliyun.com/g' /etc/chrony.conf
|
||||
```
|
||||
|
||||
2. 重启chrony服务, 并检查
|
||||
|
||||
```bash
|
||||
systemctl restart chronyd && chronyc sources
|
||||
```
|
||||
|
||||
## 安装 Docker
|
||||
|
||||
1. 更新镜像源缓存
|
||||
|
||||
```bash
|
||||
dnf makecache
|
||||
```
|
||||
|
||||
2. 安装
|
||||
|
||||
```bash
|
||||
dnf install docker
|
||||
```
|
||||
|
||||
3. 启动
|
||||
|
||||
```bash
|
||||
systemctl start docker
|
||||
systemctl enable docker
|
||||
```
|
||||
|
||||
|
||||
|
17
Docker/Docs/脚本安装Docker.md
Normal file
17
Docker/Docs/脚本安装Docker.md
Normal file
@@ -0,0 +1,17 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 脚本安装Docker
|
||||
|
||||
- 官方源
|
||||
|
||||
```bash
|
||||
curl -fsSL https://get.docker.com | bash
|
||||
```
|
||||
|
||||
- 阿里源
|
||||
|
||||
```bash
|
||||
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
|
||||
```
|
||||
|
||||
|
39
Docker/Files/cri-docker.service
Normal file
39
Docker/Files/cri-docker.service
Normal file
@@ -0,0 +1,39 @@
|
||||
[Unit]
|
||||
Description=CRI Interface for Docker Application Container Engine
|
||||
Documentation=https://docs.mirantis.com
|
||||
After=network-online.target firewalld.service docker.service
|
||||
Wants=network-online.target
|
||||
Requires=cri-docker.socket
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
TimeoutSec=0
|
||||
RestartSec=2
|
||||
Restart=always
|
||||
|
||||
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
|
||||
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
|
||||
# to make them work for either version of systemd.
|
||||
StartLimitBurst=3
|
||||
|
||||
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
|
||||
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
|
||||
# this option work for either version of systemd.
|
||||
StartLimitInterval=60s
|
||||
|
||||
# Having non-zero Limit*s causes performance problems due to accounting overhead
|
||||
# in the kernel. We recommend using cgroups to do container-local accounting.
|
||||
LimitNOFILE=infinity
|
||||
LimitNPROC=infinity
|
||||
LimitCORE=infinity
|
||||
|
||||
# Comment TasksMax if your systemd version does not support it.
|
||||
# Only systemd 226 and above support this option.
|
||||
TasksMax=infinity
|
||||
Delegate=yes
|
||||
KillMode=process
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
12
Docker/Files/cri-docker.socket
Normal file
12
Docker/Files/cri-docker.socket
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=CRI Docker Socket for the API
|
||||
PartOf=cri-docker.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=%t/cri-dockerd.sock
|
||||
SocketMode=0660
|
||||
SocketUser=root
|
||||
SocketGroup=docker
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
114
Docker/Files/daemon-original.json
Normal file
114
Docker/Files/daemon-original.json
Normal file
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"allow-nondistributable-artifacts": [],
|
||||
"api-cors-header": "",
|
||||
"authorization-plugins": [],
|
||||
"bip": "",
|
||||
"bridge": "",
|
||||
"cgroup-parent": "",
|
||||
"containerd": "/run/containerd/containerd.sock",
|
||||
"containerd-namespace": "docker",
|
||||
"containerd-plugin-namespace": "docker-plugins",
|
||||
"data-root": "",
|
||||
"debug": true,
|
||||
"default-address-pools": [
|
||||
{
|
||||
"base": "172.30.0.0/16",
|
||||
"size": 24
|
||||
},
|
||||
{
|
||||
"base": "172.31.0.0/16",
|
||||
"size": 24
|
||||
}
|
||||
],
|
||||
"default-cgroupns-mode": "private",
|
||||
"default-gateway": "",
|
||||
"default-gateway-v6": "",
|
||||
"default-network-opts": {},
|
||||
"default-runtime": "runc",
|
||||
"default-shm-size": "64M",
|
||||
"default-ulimits": {
|
||||
"nofile": {
|
||||
"Hard": 64000,
|
||||
"Name": "nofile",
|
||||
"Soft": 64000
|
||||
}
|
||||
},
|
||||
"dns": [],
|
||||
"dns-opts": [],
|
||||
"dns-search": [],
|
||||
"exec-opts": [],
|
||||
"exec-root": "",
|
||||
"experimental": false,
|
||||
"features": {},
|
||||
"fixed-cidr": "",
|
||||
"fixed-cidr-v6": "",
|
||||
"group": "",
|
||||
"hosts": [],
|
||||
"proxies": {
|
||||
"http-proxy": "http://proxy.example.com:80",
|
||||
"https-proxy": "https://proxy.example.com:443",
|
||||
"no-proxy": "*.test.example.com,.example.org",
|
||||
},
|
||||
"icc": false,
|
||||
"init": false,
|
||||
"init-path": "/usr/libexec/docker-init",
|
||||
"insecure-registries": [],
|
||||
"ip": "0.0.0.0",
|
||||
"ip-forward": false,
|
||||
"ip-masq": false,
|
||||
"iptables": false,
|
||||
"ip6tables": false,
|
||||
"ipv6": false,
|
||||
"labels": [],
|
||||
"live-restore": true,
|
||||
"log-driver": "json-file",
|
||||
"log-level": "",
|
||||
"log-opts": {
|
||||
"cache-disabled": "false",
|
||||
"cache-max-file": "5",
|
||||
"cache-max-size": "20m",
|
||||
"cache-compress": "true",
|
||||
"env": "os,customer",
|
||||
"labels": "somelabel",
|
||||
"max-file": "5",
|
||||
"max-size": "10m"
|
||||
},
|
||||
"max-concurrent-downloads": 3,
|
||||
"max-concurrent-uploads": 5,
|
||||
"max-download-attempts": 5,
|
||||
"mtu": 0,
|
||||
"no-new-privileges": false,
|
||||
"node-generic-resources": [
|
||||
"NVIDIA-GPU=UUID1",
|
||||
"NVIDIA-GPU=UUID2"
|
||||
],
|
||||
"oom-score-adjust": 0,
|
||||
"pidfile": "",
|
||||
"raw-logs": false,
|
||||
"registry-mirrors": [],
|
||||
"runtimes": {
|
||||
"cc-runtime": {
|
||||
"path": "/usr/bin/cc-runtime"
|
||||
},
|
||||
"custom": {
|
||||
"path": "/usr/local/bin/my-runc-replacement",
|
||||
"runtimeArgs": [
|
||||
"--debug"
|
||||
]
|
||||
}
|
||||
},
|
||||
"seccomp-profile": "",
|
||||
"selinux-enabled": false,
|
||||
"shutdown-timeout": 15,
|
||||
"storage-driver": "",
|
||||
"storage-opts": [],
|
||||
"swarm-default-advertise-addr": "",
|
||||
"tls": true,
|
||||
"tlscacert": "",
|
||||
"tlscert": "",
|
||||
"tlskey": "",
|
||||
"tlsverify": true,
|
||||
"userland-proxy": false,
|
||||
"userland-proxy-path": "/usr/libexec/docker-proxy",
|
||||
"userns-remap": ""
|
||||
}
|
52
Docker/Files/daemon.json
Normal file
52
Docker/Files/daemon.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"registry-mirrors": [
|
||||
"https://mirror.ccs.tencentyun.com",
|
||||
"https://docker.mirrors.ustc.edu.cn",
|
||||
"http://hub-mirror.c.163.com"
|
||||
],
|
||||
"insecure-registries": [],
|
||||
"experimental": true,
|
||||
"debug": false,
|
||||
"selinux-enabled": false,
|
||||
"default-runtime": "runc",
|
||||
"default-shm-size": "64M",
|
||||
"max-concurrent-downloads": 10,
|
||||
"max-concurrent-uploads": 10,
|
||||
"max-download-attempts": 3,
|
||||
"default-ulimits": {
|
||||
"nofile": {
|
||||
"Hard": 64000,
|
||||
"Name": "nofile",
|
||||
"Soft": 64000
|
||||
}
|
||||
},
|
||||
"default-address-pools": [
|
||||
{
|
||||
"base": "172.17.0.0/16",
|
||||
"size": 24
|
||||
}
|
||||
],
|
||||
"ip": "0.0.0.0",
|
||||
"data-root": "/var/lib/docker",
|
||||
"live-restore": true,
|
||||
"shutdown-timeout": 15,
|
||||
"log-driver": "json-file",
|
||||
"log-level": "warn",
|
||||
"log-opts": {
|
||||
"cache-disabled": "false",
|
||||
"cache-max-file": "3",
|
||||
"cache-max-size": "10m",
|
||||
"cache-compress": "true",
|
||||
"env": "os,customer",
|
||||
"labels": "somelabel",
|
||||
"max-file": "3",
|
||||
"max-size": "10m"
|
||||
},
|
||||
"raw-logs": false,
|
||||
"builder": {
|
||||
"gc": {
|
||||
"enabled": true,
|
||||
"defaultKeepStorage": "20GB"
|
||||
}
|
||||
}
|
||||
}
|
46
Docker/Files/docker-original.service
Normal file
46
Docker/Files/docker-original.service
Normal file
@@ -0,0 +1,46 @@
|
||||
[Unit]
|
||||
Description=Docker Application Container Engine
|
||||
Documentation=https://docs.docker.com
|
||||
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
|
||||
Wants=network-online.target containerd.service
|
||||
Requires=docker.socket
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
# the default is not to use systemd for cgroups because the delegate issues still
|
||||
# exists and systemd currently does not support the cgroup feature set required
|
||||
# for containers run by docker
|
||||
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
TimeoutStartSec=0
|
||||
RestartSec=2
|
||||
Restart=always
|
||||
|
||||
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
|
||||
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
|
||||
# to make them work for either version of systemd.
|
||||
StartLimitBurst=3
|
||||
|
||||
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
|
||||
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
|
||||
# this option work for either version of systemd.
|
||||
StartLimitInterval=60s
|
||||
|
||||
# Having non-zero Limit*s causes performance problems due to accounting overhead
|
||||
# in the kernel. We recommend using cgroups to do container-local accounting.
|
||||
LimitNPROC=infinity
|
||||
LimitCORE=infinity
|
||||
|
||||
# Comment TasksMax if your systemd version does not support it.
|
||||
# Only systemd 226 and above support this option.
|
||||
TasksMax=infinity
|
||||
|
||||
# set delegate yes so that systemd does not reset the cgroups of docker containers
|
||||
Delegate=yes
|
||||
|
||||
# kill only the docker process, not all processes in the cgroup
|
||||
KillMode=process
|
||||
OOMScoreAdjust=-500
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
13
Docker/Files/docker-original.socket
Normal file
13
Docker/Files/docker-original.socket
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Docker Socket for the API
|
||||
|
||||
[Socket]
|
||||
# If /var/run is not implemented as a symlink to /run, you may need to
|
||||
# specify ListenStream=/var/run/docker.sock instead.
|
||||
ListenStream=/run/docker.sock
|
||||
SocketMode=0660
|
||||
SocketUser=root
|
||||
SocketGroup=docker
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user