Java Server Application
Last updated
Was this helpful?
Last updated
Was this helpful?
We are going to use an application that was created in . It is using Spring 5 and it implements a simple REST API controller GET /hello
that returns Hello
string as a reponse. Lets get in case we don't want to build the application now.
Lets create the following directory structure with all the required files before we start.
Now we want to create Dockerfile that will create an image with demo.jar. When we start that docker image, we want to start the Sprint REST API on port 8080. Study the what each docker instruction does.
Now we can try to build.
First, check if our docker container is running.
If the docker container is up, we can try to talk to the server which is started inside the docker container.
Lets connect to the docker container and explore what is there.
To explore what exactly has happened, we can run the container in interactive mode.
The consequent question is how to stop the docker container we just started. We need do it by using container id, or at least the begging of the id string. e13
should be enough to identify the docker container and stop it.
When we include version number in a .jar
file, we need to be able to find it dynamically in docker and pass it to java -jar
as a parameter.
We can create this script, which we copy into docker image. It will find a jar
file based on a pattern we define and then uses this file as parameter for java
program to start the server.
Once build is done, we can star the docker. Study the documentation to learn how works with all the options. Here we use -d
flag to run container in detached mode. -p
flag says port mapping, from docker container to our system.