This post is very useful for those who are familiar with Docker.Will also help them who are at their beginner stage in learning docker.
As you all know,Docker is the best choice when we try to test/manage some applications in various versions or environments.
Here I am giving an example of Spinning up a NGINX container to bring a java HelloWorld application up.
In my next post, I will give you the internals of Docker Networking.
Prerequisites for this is to have Docker and Java installed in your environment.
- Create Hello World java code
public class HelloJeevanWorld
{
As you all know,Docker is the best choice when we try to test/manage some applications in various versions or environments.
Here I am giving an example of Spinning up a NGINX container to bring a java HelloWorld application up.
In my next post, I will give you the internals of Docker Networking.
Prerequisites for this is to have Docker and Java installed in your environment.
- Create Hello World java code
public class HelloJeevanWorld
{
public static void main(String[] args)
{
System.out.println("Hello Jeevan World");
}
}
- Build it
- create manifest file to create HelloJeevanWorld.java
- Create a DockerFile with below content
---------------------------------------------------
FROM java:8
CMD mkdir -p /tmp/Jeevan/
WORKDIR /tmp/Jeevan
COPY HelloJeevanWorld.java /tmp/Jeevan/
EXPOSE 8080
CMD java -jar HelloJeevanWorld.java
-------------------------------------------------
Here from attribute pulls mentioned image from docker hub/registry
CMD runs as a unix command to create a directory
WORKDIR denotes the docker working folder
COPY makes copying of java artifact from docker host to image so that it would be
avilable to container
EXPOSE exposes container to use it on port 8080.You can do it while running docker
run even as 8080:8080 (in format external port : container posrt)
CMD in last line to run java file
-Build docker java image using this DockerFile by below which created a image which
you can see by executing docker images
docker build -t JeevanHelloWorld .
-Spin up container using
docker run JeevanHelloWorld
-You can access this using http://dockerhostip:8080/ from browser
In the next posts I will discuss about Docker Port forwarding, using nginx reverse
proxy for docker hosted applications, creating doc networks and spinning up containers within the range of specific ip address.
Thanks for visiting.
Do Share My Blog -> http://TheUnixBlogOne.blogspot.in
No comments:
Post a Comment