synchronization
This commit is contained in:
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
|
Reference in New Issue
Block a user