Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

11 changes: 10 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}