Consider Yourself Dockerized!


I’ve just managed to “Dockerize” my base SpringBoot application, so I’m now able to use this as a template for future services. I’d wasted some time following various confusing tutorials, but it turned out to be very simple in the end.

Create Dockerfile

Create a new file in the root directory of the SpringBoot app (on the same level as src folder, pom.xml etc.) simply called Dockerfile (no extension) and put in the following:

FROM java:8
ADD target/MyBuiltApp.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

Build Docker Image

Instruct Docker to build the image, and tag it as mydockerizedservice:

NOTE: You must actually build your application in Maven first, otherwise there might not be anything to find at target/…

$ mvn -U clean install
$ docker build -t mydockerizedservice .

Run Docker Container

To initially run a new container from this image:

$ docker run -p 8765:8080 -t mydockerizedservice

To stop and re-run this container:

$ docker ps

This gives us the following Container ID for our service: 51ed23ae9b5f

Now stop the service:

$ docker stop 51ed23ae9b5f

And re-start the existing Container:

$ docker start 51ed23ae9b5f

And that is pretty much it. I’m no Docker expert, evidently, but I’m happy to answer any questions related to this. And I’m spent.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s