Go的时间不适用于从头开始的docker形象

转到代码:

package main import ( "fmt" "time" ) func main() { var local,_ = time.LoadLocation("Asia/Shanghai") fmt.Println(time.Now()) fmt.Println(time.Now().In(local)) } 

Dockerfile:

 FROM scratch COPY ./main /main CMD [ "/main" ] 

build.sh:

 rm -rf main CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main . docker build -t hello-go . docker run hello-go 

所有文件都在一个名为hello-go的文件夹中。 当我在我的osx中运行Go代码时。 有用。

 ➜ hello-go go run main.go 2017-12-13 21:50:53.482933 +0800 CST m=+0.000350077 2017-12-13 21:50:53.483007 +0800 CST 

当我build立docker图像并启动它。 一个这样的错误:

 ➜ hello-go ./build.sh Sending build context to Docker daemon 1.937MB Step 1/3 : FROM scratch ---> Step 2/3 : COPY ./main /main ---> 80da783f6c5d Step 3/3 : CMD /main ---> Running in 85cb022b3ce2 ---> 485ddd3a08dd Removing intermediate container 85cb022b3ce2 Successfully built 485ddd3a08dd Successfully tagged hello-go:latest 2017-12-13 13:52:59.861173734 +0000 UTC m=+0.000252335 panic: time: missing Location in call to Time.In goroutine 1 [running]: time.Time.In(0xbe846a0ef355744e, 0x4d607, 0x539b80, 0x0, 0x0, 0x0, 0xc420037f70) /usr/local/go/src/time/time.go:1073 +0xc0 main.main() /Users/liujichun/Desktop/workspace/docker/hello-go/main.go:11 +0xee ➜ hello-go 

我知道临时图像是空的。 我该怎么做才能做到。