Today, when I was running my Golang code in production, I suddenly got an error. I felt very strange. It was running fine locally, but when I put it into the server, I got an error.

Found a way to solve the problem, by the way record, for the reference of each big guy


1. Problem description

Error code: error code: error code: error code: error code: error code: error code: error code: error code

could not load time location: unknown time zone Asia/Shanghai
Copy the code

2. Cause of the problem

This was awkward, because it ran fine locally, so I looked it up and found out that the Base Image I was using was Alpine. Of course, if you were using BusyBox, there would be a problem too, because they don’t have the timezone configuration required by Go.

Problem solving

The solution is to install the tzdata package in the image by adding the following section to the Dockerfile.

The FROM golang: 1.14.3 - alpine... . FROM alpine ... . RUN apk update && apk add tzdata ... .Copy the code