As, we have mentioned earlier that docker can execute any application.
Here, we are creating a Java application and running by using the docker. This example includes the following steps.
- Create a directory Directory is required to organize files. Create a director by using the following command.
- Create a Java File Now create a Java file. Save this file as Hello.java file.
- Create a Dockerfile After creating a Java file, we need to create a Dockerfile which contains instructions for the Docker. Dockerfile does not contain any file extension. So, save it simple with Dockerfile name.
- Build Docker Image After creating Dockerfile, we are changing working directory.
- Run Docker Image After creating image successfully. Now we can run docker by using run command. The following command is used to run java-app.
Hello.java
Dockerfile
See, your folder inside must look like the below.
Now, create an image by following the below command. we must login as root in order to create an image. In this example, we have switched to as a root user. In the following command, java-app is name of the image. We can have any name for our docker image.
After successfully building the image. Now, we can run our docker image.
Here, we can see that after running the java-app it produced an output.
Now, we have run docker image successfully on your system. Apart from all these you can also use other commands as well.
Reference:
I like your post very much. DevOps Training in Bangalore | Certification | Online Training Course institute | DevOps Training in Hyderabad | Certification | Online Training Course institute | DevOps Training in Coimbatore | Certification | Online Training Course institute | DevOps Online Training | Certification | Devops Training Online
ReplyDelete