【问题标题】:I need help about dockerfile我需要有关 dockerfile 的帮助
【发布时间】:2021-12-09 13:35:59
【问题描述】:

我现在需要帮助 我的项目是golang服务器 此服务器创建 pdf 文件(github.com/jung-kurt/gofpdf) 我正在使用韩文字体文件(https://fonts.google.com/specimen/Nanum+Gothic) 我可以看到效果很好的 pdf 文件

但是在我看到错误信息后制作一个 docker 图像 (错误:stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf:没有这样的文件或目录)

为什么?我是 docker 文件的副本

COPY /cert/Wildcard.sunmediscreen.com.key.pem /go/src/pdf.server/cert/
COPY /cert/Full_Wildcard.sunmediscreen.com.pem /go/src/pdf.server/cert/

COPY /templates/font/NanumGothic-Bold.ttf /go/src/pdf.server/templates/font/
COPY /templates/font/NanumGothic-ExtraBold.ttf /go/src/pdf.server/templates/font/
COPY /templates/font/NanumGothic-Regular.ttf /go/src/pdf.server/templates/font/

这是一个 dockerfile 日志

Step 21/28 : COPY /cert/Wildcard.sunmediscreen.com.key.pem /go/src/pdf.server/cert/
 ---> b4e2c2a498f0
Step 22/28 : COPY /cert/Full_Wildcard.sunmediscreen.com.pem /go/src/pdf.server/cert/
 ---> eb613bcfd946
Step 23/28 : COPY /templates/font/NanumGothic-Bold.ttf /go/src/pdf.server/templates/font/
 ---> 292667b551ec
Step 24/28 : COPY /templates/font/NanumGothic-ExtraBold.ttf /go/src/pdf.server/templates/font/
 ---> e9d027f3cefb
Step 25/28 : COPY /templates/font/NanumGothic-Regular.ttf /go/src/pdf.server/templates/font/
 ---> 2a9c96090552

这是一个golang

fontDir := filepath.Join(os.Getenv("GOPATH"), "src/pdf.server/templates/font")
    pdf.AddUTF8Font("NanumGothic", "", filepath.Join(fontDir, "NanumGothic-Regular.ttf"))
    pdf.AddUTF8Font("NanumGothic", "B", filepath.Join(fontDir, "NanumGothic-Bold.ttf"))
    pdf.AddUTF8Font("NanumGothic", "EB", filepath.Join(fontDir, "NanumGothic-ExtraBold.ttf"))

只是字体文件有问题

请帮帮我


os.Getenv("GOPATH") 这条路没问题 因为pem文件路径没有关于tls设置的问题

crtpath := filepath.Join(os.Getenv("GOPATH"), "src/pdf.server/cert/Full_Wildcard.sunmediscreen.com.pem") keypath := filepath.Join(os.Getenv("GOPATH"), "src/pdf.server/cert/Wildcard.sunmediscreen.com.key.pem")

var x509 tls.Certificate
x509, err := tls.LoadX509KeyPair(crtpath, keypath)
if err != nil {
    panic(err)
}

【问题讨论】:

  • 您可以尝试在您的程序中打印出os.Getenv("GOPATH"),并确保字体已正确安装在docker容器中。
  • os.Getenv("GOPATH") 这个路径没有问题,因为pem文件路径没有关于tls设置的问题
  • 您以什么用户身份运行COPY 命令,您以什么用户身份运行服务器?如果您以 root 身份复制但以非 root 用户身份运行,则可能是权限问题。

标签: docker go fonts dockerfile


【解决方案1】:

err: stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory中的路径错过了根目录/,应该是/go/src/pdf.server/templates/font/NanumGothic-Regular.ttf

fmt.Println(os.Stat("go/src/pdf.server/templates/font/NanumGothic-Regular.ttf"))
fmt.Println(os.Stat("/go/src/pdf.server/templates/font/NanumGothic-Regular.ttf"))

输出:

<nil> stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory
<nil> stat /go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory

【讨论】:

  • 这只是 err log err: stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: 没有这样的文件或目录我添加根目录(os.Getenv("GOPATH ") + "src/pdf.server/templates/font" + "NanumGothic-Regular.ttf")
猜你喜欢
  • 2015-08-29
  • 1970-01-01
  • 2022-11-28
  • 2022-01-08
  • 2019-05-17
  • 1970-01-01
  • 2022-11-24
  • 2015-06-23
  • 2014-12-26
相关资源
最近更新 更多