Deploy a Java application through Docker
Step by Step Guide to deploy a Java application using Docker
- Install the docker with “Sudo apt install "docker.io” I’m using the centos instance and docker is already installed in my EC2 instance.
- Check whether the docker service is running or not.
- Created a folder called Projects
4. Checked and confirmed that there is no file created in the Projects Directory.
5. Create folder java-app within the Project directory
6. Created the file hello.java within java-app
7. Put the code in the Hello.Java
8. We can use the Javac to compile the code but unfortunately we don't have the “java” installed in my system.
9. So Install Openjdk with the following command: Sudo apt install openjdk-11-jdk-headless
- We can use Javac to compile the code.
11. Now the file has been compiled
12. Post this we can create a dockerfile.
13. Once the docker file is created we have to build the image with the following command “docker build-t java-app:latest".
14. We can check with “docker images" command if the image is available.
15. & finally, we ran the code with the "docker run" command & Container has been running sucessfully.
Thank You !!
Happy Learning!!