Docker Container Java System Time Issue

Viewed 358

I stumbled upon an issue with Docker container based off of Java wrap my head around it. So here's the code

import java.time.Instant;
import java.lang.System;
public class UnixTime {
    public static void main(String[] args){
        Instant now = Instant.now();
        System.out.println("Now : " + now);
        System.out.println("Unix: " + now.getEpochSecond());
    }
}

Once you compile it locally with javac UnixTime.java and run it as java UnixTime you will get something like this

% java UnixTime
Now : 2020-03-19T05:02:19.316Z
Unix: 1584594139

Now, let's run it on Docker container based off of openjdk:8-jre

% docker run --rm -v $PWD:/usr/myapp -w /usr/myapp openjdk:8-jre java UnixTime
Now : 2020-03-11T17:29:07.368Z
Unix: 1583947747

Date and time is completely off. Why is that? Where's it coming from ?

0 Answers
Related