Generate Docker Image with Buildpacks
In this year the Docker technology is very common use in our tech industry, they simplify our development until deployment process. But…
Generate Docker Image with Buildpacks
In this year the Docker technology is very common use in our tech industry, they simplify our development until deployment process. But, it’s also need a learning curve to understand how to write Dockerfile correctly to build docker images our applications.
Recently, there is a approach that can build docker images easier on our application, it is Buidpacks. Buildpacks can help us to transform our source code into docker image. So we don’t need to write docker file manually. It’s so magic right? For more detail information we can check to the website https://buildpacks.io/. They claim they can scan our source code, dependencies with follow the standard of security, caching, compressing, etc. One of the example of buildpacks is packeto. It supports many language like Java, Go, Python, etc.
Previously, I already written the docker file to this service and docker image successfully generated, the steps are:
- Write the dockerfile
FROM openjdk:21-jdk-slim
COPY target/midtrans-0.0.1-SNAPSHOT.jar /app/midtrans-0.0.1-SNAPSHOT.jar
WORKDIR /app
CMD ["java", "-jar", "midtrans-0.0.1-SNAPSHOT.jar"]
- Execute the command to generate docker image
docker build . -t [imagename]:[version]
- Execute the command to run the docker image with define the external port you want to expose
docker run -p [external-port]:[internal-port-docker-host] [image-name]:[version]
- Check the docker image
docker images

That is an example of how to write in docker file but with basic command into simple service. Now, let’s try to implement paketo buildpacks into this service.
We need to mention in our pom.xml the docker username followed by the image name and version you want to expose. In this case I will use from artifactId & version that already defined in the top of the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>[your-docker-username]/${project.artifactId}:${project.version}</name>
</image>
</configuration>
</plugin>
</plugins>
</build>
After that the buildpacks will generate the docker image by this command:
mvn spring-boot:build-image
In the first time we generate it will take more time because it is going to download all packages from paketo buildpacks into our local.


Let’s try to run the docker image with the same above command.

Now we can see in the docker dashboard and we can test into our endpoint with port 8888 to hit the service:


We can check the image generated by buildpacks vs by writing manually.
docker image by written manually:

docker image by buildpacks:

We can see the size of both are different. Why? because it’s difficult to follow the best practices when writing into a docker file like how to compress our components, how to cache multiple layers. But with buildpacks we can see the size of the image is smaller, it reduces from 490 MB to 356 MB. There are advantages & disadvantages between buildpacks and docker file. If we use the docker file by written manually is more flexible to maintain custom requirements.
메타데이터
- post_id
- 55fcd223446f
- slug
- generate-docker-image-with-buildpacks-55fcd223446f
- url
- https://medium.com/@nfapril/generate-docker-image-with-buildpacks-55fcd223446f
- canonical_url
- https://medium.com/@nfapril/generate-docker-image-with-buildpacks-55fcd223446f
- author_url
- https://medium.com/@nfapril
- status
- ok
- fetched_at
- 2026-07-23 01:32:44