我需要关于Dockerfile的帮助。

huangapple go评论82阅读模式
英文:

I need help about dockerfile

问题

我需要帮助。
我的项目是使用Golang编写的服务器。
这个服务器用于创建PDF文件(github.com/jung-kurt/gofpdf)。
我使用了韩文字体文件(https://fonts.google.com/specimen/Nanum+Gothic)。
我可以看到生成的PDF文件效果很好。

但是,在创建Docker镜像后,我看到了错误消息:
(err: stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory)

为什么会这样?我在Dockerfile中进行了复制操作:

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)
}

英文:

i need help now
my project are golang server
this server are create pdf file(github.com/jung-kurt/gofpdf)
and i am use korean font file(https://fonts.google.com/specimen/Nanum+Gothic)
i can see good result pdf file

but make a docker image after i can see error message
(err: stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory)

why? i am copy at docker file

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/

this is a dockerfile log

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

and this is a 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"))

just font file has a problem

please help me


os.Getenv("GOPATH")
this path are no problem
because pem file path has not problem about tls setting

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)
}

答案1

得分: 0

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
英文:

path in err: stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory missed the root directory /, it should be /go/src/pdf.server/templates/font/NanumGothic-Regular.ttf.

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

output:

&lt;nil&gt; stat go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory
&lt;nil&gt; stat /go/src/pdf.server/templates/font/NanumGothic-Regular.ttf: no such file or directory

huangapple
  • 本文由 发表于 2021年10月23日 11:10:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/69684814.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定