We will make a docker file for a simple java application so firstly we have to clone it.
Copy this link: https://github.com/prem14choudhary/simple-java-docker.git
Hereās the solution':
ssh to your EC2 instance.
Run for making project folder: mkdir projects
Run for cloning it: git clone https://github.com/prem14choudhary/simple-java-docker.git
Run : cd simple-java-docker/
Run for removing existing docker file: rm -v Dockerfile
Run to make new docker file: vim Dockerfile.
Now i will giving the script, you have to enter in that vim editor. I will also giving explanation in brackets() donāt insert that.
FROM openjdk:17-jdk-alpine
(for the enviroment and libraries the application need)
WORKDIR /app
(for making a folder in the container where the the source code will be placed)
COPY src/Main.java /app/Main.java
(for copy the source code in the container folder)
RUN javac Main.java
(for compiling the Main.java after the container will be created)
CMD [ājavaā,āMainā]
(it will run the container after creation)
To save this enter: esc button then :wq
Your Docker file is created.
Hari om tatsat