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 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:
ADD target/MyBuiltApp.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.