Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker 版本日志无法输出到文件 #1027

Open
magicds opened this issue Mar 29, 2022 · 4 comments
Open

docker 版本日志无法输出到文件 #1027

magicds opened this issue Mar 29, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@magicds
Copy link

magicds commented Mar 29, 2022

Describe the bug

docker 版本日志无法输出到文件

https://hub.docker.com/r/ffdfgdfg/nps

日志仅能通过 docker logs 命令查看, 无法输出到文件。

尝试过如下方式均无法获取:

  1. 配置文件配置 log_path, docker 挂载目录 =>目录下无文件输出
  2. sudo docker cp nps:/var/log/nps.log nps.log => No such container:path: nps:/var/log/nps.log
@magicds magicds added the bug Something isn't working label Mar 29, 2022
@magicds magicds changed the title dockers docker 版本日志无法输出到文件 Mar 29, 2022
@aschenmaker
Copy link

Show your config file nps.conf

看看配置文件

@magicds
Copy link
Author

magicds commented Mar 31, 2022

@aschenmaker

# log level LevelEmergency->0  LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
log_level=7
log_path=nps.log

@aschenmaker
Copy link

问题我认为是dockerfile的原因,dockerfile 没有一个启动参数。

here <-

	if len(os.Args) > 1 && os.Args[1] == "service" {
		_ = logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`)
	} else {
		_ = logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`)
	}

dockerfile CMD

VOLUME /conf
CMD ["/nps"]

修改一下启动命令重新打包镜像 挂载log volumn就可以了

@aschenmaker
Copy link

我编译了一个 测试了一下没有问题

docker run -d --name nps-as --net=host -v /root/nps/conf/:/conf -v /var/log/nps/:/logs   aschenmaker/nps:v0.0.1

conf/nps.conf

log_level=7
log_path=/logs/nps.log

日志

tail -f /var/log/nps/nps.log

dockerfile

FROM golang:1.15 as builder
ARG GOPROXY="https://goproxy.cn,direct"
WORKDIR /go/src/ehang.io/nps
COPY . .
RUN go get -d -v ./... 
RUN CGO_ENABLED=0 go build -ldflags="-w -s -extldflags -static" ./cmd/nps/nps.go

FROM scratch
COPY --from=builder /go/src/ehang.io/nps/nps /
COPY --from=builder /go/src/ehang.io/nps/web /web
VOLUME /conf
CMD ["/nps", "service"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants