diff --git a/Dockerfile b/Dockerfile index ca7847b..eb3be25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,23 @@ -# stable official Java runtime base image -FROM openjdk:17-jdk-alpine -# metadata -LABEL maintainer="your-email@example.com" -LABEL version="1.0" -LABEL description="A simple Java application" -# working directory +# BASE IMAGE - which provides the working environment +FROM openjdk:17-jdk-alpine + +#WORKING DIRECTORY - on which directory will my container run.... if it is copied from source WORKDIR /app -# Copy source code into the container -COPY src/Main.java /app/Main.java +# Copy the source code from HOST to working directory +COPY . . -# Compile the Java code -RUN javac Main.java +# Install timezone data using Alpine Package Manager +RUN apk add --no-cache tzdata -# Run the Java application when the container starts +# Set timezone equal to IST +ENV TZ=Asia/Kolkata + +# Compile the code +RUN javac src/Main.java -d /app + +# Run the Application CMD ["java", "Main"] + diff --git a/src/Main.java b/src/Main.java index b6d2bd7..a7dc37d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,8 +1,17 @@ +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.TimeZone; public class Main { public static void main(String[] args) { - Date currentDate = new Date(); + Date now = new Date(); + + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z"); + + sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); + + String currentDate = sdf.format(now); + System.out.println("Hello, Docker! Current date: " + currentDate); } }