Update the ZONEINFO environment variable with the correct path to the zoneinfo.zip fileĬOPY -from=0 /app/myapp. Copy the time zone info from the build image.Runtime.GOROOT() + "/lib/time/zoneinfo.zip",įor this approach, there are two things to do to get the time zone info data available at runtime. /usr/ share/lib/zoneinfo, IRIX 6 has /usr/lib/locale/TZ. src/time/zoneinfo_unix.go:21 // Many systems use /usr/ share/zoneinfo, Solaris 2 has You can find here info on all environments, but below you can check where the time zone info is in Unix systems. How to fix it?įirst, let's see where our Go app retrieves the time zone information from. In my case, there is no time zone information that I needed. We all love the scratch image because of its size, but because it is an image for a bare-bone container, it doesn't have all dependencies you expect to have when running an app within it. This problem stems from using the scratch image in my Docker multi-stage build. It seems that either the file cannot be found or that the used time zone is not in the available zoneinfo.zip file. Open /usr/local/go/lib/time/zoneinfo.zip: no such file or directory For example, I have also tried this with the golang:alpine image, and this was the output: Local time: 2020- 11- 07 08: 29: 59. You might get different errors based on the image you use for building the app. 1326111 + 0000 UTCĪs you might have seen, I've used Go 1.14 in my examples. RUN CGO_ENABLED= 0 GOOS=linux go build -o myapp Now, let's build and run the app inside a Docker container, with a nice multi-stage build. In any case, you should get some results. It might not be the results you expected, but that's because the instance on which the code is run might have different time settings. If you run this in some Go playground, it will show the results. Tz, err := time.LoadLocation("Europe/Sarajevo")įmt.Println("Sarajevo time: ", time.Now(). After the changes got deployed to the test environment, I checked if the service is working correctly and found this error: 2020/ 11/ 06 08: 29: 33 error occurred during import and sync execution:įmt.Println("UTC time: ", time.Now().UTC()) As the process goes, I made the changes, tested it out locally on my machine, and pushed the code to the Github repo. Yesterday I received a requirement for one of my Go services to convert some data from a specific timezone to UTC.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |