When you take a look at the Java Official Docker images, you will immediately notice how fat they are: a whopping 243MB announced for a simple Java 8 JDK base image! It takes forever to download them from a regular DSL connection here.
Usually, your Dockerfile for Java apps starts with something like:
|
|
Just try the following command: (you must have docker installed)
|
|
It should output something like:
|
|
Wow! 643MB just to be able to launch a Java application inside a container. And you don’t even have bundled your application yet!
Alpine Linux
Alpine Linux is a very small Linux distribution based on Busybox. It’s very small, only 5MB once pulled from Docker Hub!
The Alpine Java is of course bigger but way smaller than Java official’s one. This is the size of the latest Alpine Java using Oracle 8 JRE (Server JRE):
|
|
That’s almost 500MB smaller than the official one! Here the docker file we use to run our spring boot powered backend:
|
|
And the entrypoint.sh script:
|
|
Lighter docker images are essential when deploying your app frequently. The bigger the image is, the more time it takes for Docker to download and extract it.
Other Tips
Take a look at Best practices for writing Docker images on the Docker website. It contains many tips and tricks to reduce your docker images size.
Conclusion
It seems so easy, it’s almost magic. It works great for our backend written with Java 8 and Spring Boot. Why not for you?
Be the first to comment
Thank you
Your comment has been submitted and will be published once it has been approved.
OK
OOPS!
Your post has failed. Please return to the page and try again. Thank You!
OK