[英]Docker unable to locate package (wkhtmltopdf) while building
在进行故障排除时,我遇到了不同的错误:
...
Err:1 http://deb.debian.org/debian bullseye InRelease
Temporary failure resolving 'deb.debian.org'
...
我猜这与我的防火墙设置(nftables)运行有关
docker run busybox nslookup google.com
给我;; connection timed out; no servers could be reached
;; connection timed out; no servers could be reached
因此 docker 与外部没有连接?
开发环境: Ubuntu 22.04
产品环境: debian 10.12 64bit / Linux 4.19.0-20-amd64
FROM node:slim
# Install wkhtmltopdf
RUN apt-get update
RUN apt-get install -y wkhtmltopdf
RUN npm install -g pm2@latest
WORKDIR /var/api
COPY . .
RUN npm i
EXPOSE 10051-10053
# Start PM2 as PID 1 process
ENTRYPOINT ["pm2-runtime"]
CMD ["process.json"]
在我的开发系统 (Ubuntu 22.04) 上构建此文件时,它工作正常。
Building backend
Sending build context to Docker daemon 159.2kB
Step 1/10 : FROM node:slim
---> 6c8b32c67190
Step 2/10 : RUN apt-get update
---> Using cache
---> b28ad6ee8ebf
Step 3/10 : RUN apt-get install -y wkhtmltopdf
---> Running in 2f76d2582ac0
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package wkhtmltopdf
The command '/bin/sh -c apt-get install -y wkhtmltopdf' returned a non-zero code: 100
ERROR: Service 'backend' failed to build : Build failed
apt-get install -y wkhtmltopdf
可以很好地安装 package。/etc/apt/sources.list
添加了不同的回购协议根据Docker 文档:
在 RUN 语句中单独使用 apt-get update 会导致缓存问题,并且后续的 apt-get install 指令会失败。
因此,对于您的情况,您应该这样做:
RUN apt-get update && apt-get install -y wkhtmltopdf
代替:
RUN apt-get update
RUN apt-get install -y wkhtmltopdf
我找到了解决方案,问题是 nftables 和 docker。 Docker 将 iptables 规则添加到规则集中,我所要做的就是:
- 使用 ip 和 ipv6 表而不是 inet
- 完全按照 iptables 命名所有链:INPUT、OUTPUT & FORWARD
来源: https ://ehlers.berlin/blog/nftables-and-docker/
我没有解决问题,而是下载了.deb
并安装了它,在我的例子中是gdebi
,但你也可以使用dpkg
。
RUN echo "### Install wkhtmltopdf ###" \
&& wget -nv -O /tmp/wkhtmltopdf.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb \
&& gdebi --non-interactive /tmp/wkhtmltopdf.deb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.