官方Certbot Docker镜像默认无NGINX插件,求添加方法及解决方案
解决方案
1. 为官方Certbot镜像添加NGINX插件
官方Alpine版Certbot镜像默认未包含nginx插件,但可以通过PyPI包管理器安装。创建如下自定义Dockerfile:
FROM certbot/certbot:latest RUN pip install certbot-nginx
执行构建命令生成自定义镜像:
docker build -t my-certbot-with-nginx .
使用该镜像执行证书申请命令即可:
docker run --rm my-certbot-with-nginx certbot --nginx -d example.com
2. 替代方案
- 直接使用官方组合镜像:官方提供了
certbot/nginx镜像,已预装Certbot及nginx插件,无需额外配置,直接运行:docker run --rm certbot/nginx certbot --nginx -d example.com - Webroot模式绕开插件依赖:若不想安装插件,可采用webroot模式获取证书。需先确保你的Nginx已配置对应域名的webroot路径,然后执行:
获取证书后,手动将证书路径配置到Nginx的SSL配置中即可。docker run --rm -v /your/local/webroot:/var/www/html certbot/certbot certbot certonly --webroot -w /var/www/html -d example.com
3. Alpine环境安装Certbot NGINX插件的方法
Alpine官方软件源中确实没有python3-certbot-nginx包,唯一可行的方式是通过pip安装:
pip install certbot-nginx
官方Certbot镜像已自带pip工具,直接在容器内执行上述命令即可完成插件安装。
内容的提问来源于stack exchange,提问作者DrusePstrago
相关产品推荐
相关产品推荐

