【问题标题】:Docker unable to locate package (wkhtmltopdf) while buildingDocker在构建时无法找到包(wkhtmltopdf)
【发布时间】:2022-06-15 21:51:15
【问题描述】:

系统

开发环境:Ubuntu 22.04
产品环境:debian 10.12 64bit / Linux 4.19.0-20-amd64

我的节点后端文件夹中的 Dockerfile

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 可以正常安装软件包。
  • /etc/apt/sources.list添加了不同的存储库
  • 我知道它的包https://packages.debian.org/buster/wkhtmltopdf (?)
  • 一些疑难解答。

【问题讨论】:

    标签: linux docker ubuntu debian apt


    【解决方案1】:

    根据Docker docs

    在 RUN 语句中单独使用 apt-get update 会导致缓存问题,并且后续的 apt-get 安装指令会失败。

    所以对于你的情况,你应该这样做:

    RUN apt-get update && apt-get install -y wkhtmltopdf 
    

    代替:

    RUN apt-get update
    RUN apt-get install -y wkhtmltopdf
    

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 2016-02-28
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多