docker多阶段构建时无法在golang beego框架中使用.conf

在Beego(Golang框架)中有一个.conf文件,用于声明整个应用程序的变量。 Beego支持beego.AppConfig.String(key)在任何地方获取值。 我通常在本地计算机上使用它(不在docker中)。 但是当我在多阶段构建docker时,该文件无法使用(打印时得到空值)</ p>

我在MacOS上使用docker 18.03 </ p>

conf / app.conf </ p>

  MysqlHost = 127.0.0.1 
MysqlPort = 3306
</ code> </ pre>

setting.go < / p>

  MysqlHost = beego.AppConfig.String(“ MysqlHost”)
</ code> </ pre>

但是在打印时却空了< / p>

这是我的Dockerfile </ p>

  FROM golang:1.11-alpine AS build_base 

运行apk添加bash ca证书git gcc g ++ libc -dev
RUN mkdir / bus_serivce
WORKDIR / bus_service

ENV GO111MODULE = on

COPY go.mod。
COPY go.sum。

RUN go mod下载
COPY。 。
RUN CGO_ENABLED = 0 GOOS = linux GOARCH = amd64 go build -a -installsuffix cgo -o / go / bin / bus_serivce

FROM alpine
RUN apk添加ca证书
COPY --from = build_base / go / bin / bus_serivce / bus_serivce
ENTRYPOINT [“ / bus_serivce”]
</ code> </ pre>

在docker构建并运行后,一切正常,但是我无法在.conf文件中找到该值 我在本地计算机上(不是在docker中)
有人可以帮助我吗。
非常感谢</ p>
</ div>

展开原文

原文

There is a .conf file in Beego (Golang framework), it is used for declare variable for whole app. Beego support beego.AppConfig.String(key) to get a value in anywhere. I use it on local machine (not in docker) normally. But when I build on docker multi-stage, that file can not be used (got empty value when printed)

I use docker 18.03 on MacOS

conf/app.conf

MysqlHost = 127.0.0.1
MysqlPort = 3306

setting.go

MysqlHost      = beego.AppConfig.String("MysqlHost")

But I got empty when print it

This is my Dockerfile

FROM golang:1.11-alpine AS build_base

RUN apk add bash ca-certificates git gcc g++ libc-dev
RUN mkdir /bus_serivce
WORKDIR /bus_service

ENV GO111MODULE=on

COPY go.mod .
COPY go.sum .

RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /go/bin/bus_serivce

FROM alpine
RUN apk add ca-certificates
COPY --from=build_base /go/bin/bus_serivce /bus_serivce
ENTRYPOINT ["/bus_serivce"]

After docker build and run, everything works find but I can not get the value in .conf file like I did in local machine (not in docker) Can anyone help me. Thanks a lot

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐