docker - 如何在独立容器中配置 LetsEncrypt-Cerbot
问题描述
我试图找到关于在 docker-container 中运行 certbot 的简单文档,但我能找到的只是运行 certbot + webserver 等的复杂指南。官方页面有点没用...... https://hub.docker。 com/r/certbot/certbot/。我已经有独立于我的网站的网络服务器,我也想自己运行 certbot。
谁能给我一些指导,告诉我如何mysite.com
使用/opt/mysite/html
.
由于我已经在端口 443 和 80 上提供了服务,因此如果 certbot 需要,我正在考虑使用“主机网络”,但我真的不明白为什么当我的网站已经通过 443 提供服务时它需要访问 443。
我找到了类似的东西来生成一个 certbot 容器,但我不知道如何“使用它”或告诉它为我的站点生成一个证书。
例如:
WD=/opt/certbot
mkdir -p $WD/{mnt,setup,conf,www}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'
services:
certbot:
image: certbot/certbot
volumes:
- type: bind
source: /opt/certbot/conf
target: /etc/letsencrypt
- type: bind
source: /opt/certbot/www
target: /var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
EOF
chmod +x docker-compose.yaml
这个链接有一些接近我需要的东西,(显然我需要以某种方式给它我的域作为参数!)
docker run -it --rm \
-v certs:/etc/letsencrypt \
-v certs-data:/data/letsencrypt \
deliverous/certbot \
certonly \
--webroot --webroot-path=/data/letsencrypt \
-d api.mydomain.com
我喜欢让一切都保持“隔离”,所以我希望让 certbot 在它自己的容器中运行,并将 nginx/webserver 配置为使用证书 seperatley,而不是让 certbot 自动配置 nginx 或在与 webserver 相同的堆栈中运行。
解决方案
好吧,我最近一直在学习很多关于 docker 的知识,而且我最近学会了如何查看Dockerfile
. certbot dockerfile给了我更多提示。
基本上,您可以将以下内容附加到您的docker-compose.yaml
后面,就像certbot
在 CLI 上附加一样。我将使用我的工作配置进行更新,但由于“每小时 5 次身份验证失败的速率限制”而被阻止:(
见Entrypoint
_DockerFile
ENTRYPOINT [ "certbot" ]
Docker-Compose.yaml:
command: certonly --webroot -w /var/www/html -d www.examplecom -d examplecom --non-interactive --agree-tos -m example@example.com
一旦我得到它的工作,我将更新我的完整配置,并将包括变量以利用.env
文件。
完整配置示例:
WD=/opt/certbot
mkdir -p $WD/{setup,certbot_logs}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'
services:
certbot:
container_name: certbot
hostname: certbot
image: certbot/certbot
volumes:
- type: bind
source: /opt/certbot/certbot_logs
target: /var/log/letsencrypt
- type: bind
source: /opt/nginx/ssl
target: /etc/letsencrypt
- type: bind
source: ${WEBROOT}
target: /var/www/html/
environment:
- 'TZ=${TZ}'
command: certonly --webroot -w /var/www/html -d ${DOMAIN} -d www.${DOMAIN} --non-interactive --agree-tos --register-unsafely-without-email ${STAGING}
EOF
chmod +x docker-compose.yaml
cd $WD/setup
变量:
cat << 'EOF'>.env
WEBROOT=/opt/example/example_html
DOMAIN=example.com
STAGING=--staging
TZ=America/Whitehorse
EOF
chmod +x .env
NGinx:
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
location /.well-known/acme-challenge/ {
proxy_pass http://localhost:8575/$request_uri;
include /etc/nginx/conf.d/proxy.conf;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443;
server_name www.example.com example.com;
# ssl_certificate /etc/ssl/live/example.com/fullchain.pem;
# ssl_certificate_key /etc/ssl/live/example.com/privkey.pem;
ssl_certificate /etc/ssl/fake/fake.crt;
ssl_certificate_key /etc/ssl/fake/fake.key;
location / {
proxy_pass http://localhost:8575/;
include /etc/nginx/conf.d/proxy.conf;
}
)
推荐阅读
- python - Tkinter 的问题 - 继承问题
- java - 将 JNA 结构的集合传递给本地方法
- php - Laravel 服务器不断启动和关闭
- javascript - 使用角度导入excel文件并使用.net核心中的REST API将excel表数据转换为数组
- python - 模块 browserhistory 似乎不起作用并引发 KeyError
- java - 在 Apache 的 Lucene 中使用默认和自定义停用词(奇怪的输出)
- google-apps-script - 将 *.googleusercontent.com 添加到授权的 JavaScript 来源
- python - 无法正确格式化 API json 输出
- android - LocationComponent com.mapbox.mapboxsdk.maps.MapboxMap.getLocationComponent()' 在空对象引用上
- javascript - 加入多个表:在 asp.net mvc 中将项目从表列表编辑和更新为模式