DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Build and Push Spring Boot Docker Images With boost-maven-plugin

Build and Push Spring Boot Docker Images With boost-maven-plugin

Interested in building microservice applications with Spring Boot and housing them in a Docker image? Learn how in this post!

Anjum Fatima user avatar by
Anjum Fatima
·
Jan. 16, 19 · Tutorial
Like (11)
Save
Tweet
Share
15.84K Views

Join the DZone community and get the full member experience.

Join For Free

Do you want an efficient Docker image of your Spring Boot application? Do you want a Maven plugin to do the job? If the answer is yes, you are in the right place. The boost-maven-plugin provides a simple and efficient way to build your Docker image without even having to write a Dockerfile.

Writing a Dockerfile to create an efficient Docker image requires more than just an understanding of the application. It requires optimization techniques and capabilities in Docker that go beyond a simplistic Dockerfile approach. The Boost Maven plugin provides a functionality to build and push layered Docker images of Spring Boot applications using Liberty.

In a previous blog post, Creating dual layer Docker images for Spring Boot apps, we showed how to create an efficient Docker image by writing the Dockerfile yourself. Using the Boost Maven plugin, you can create an efficient Docker image with only minimal knowledge of Docker. Just install and run Docker on your machine to get started.

Configuring the Boost Maven plugin

In your Spring Boot application, after the spring-boot-maven-plugin entry in the pom.xml file, add another entry for the boost-maven-plugin in the <plugins> section:

<plugin>
  <groupId>io.openliberty.boost</groupId>
  <artifactId>boost-maven-plugin</artifactId>
  <version>0.1</version>
</plugin>

This adds the boost-maven-plugin to your project.

Building the Docker image

You can build the Docker image either by adding an execution goal to the pom.xml or by running the goal directly in the terminal.

The docker-build goal creates a Liberty-specific Dockerfile and builds the Docker image. If a Dockerfile already exists in that location, you’ll see a warning and the existing Dockerfile is used to create the Docker image.

The build creates a Docker image with a default repository name as ${project.artifactId} and a default tag latest.

Updating the pom.xml

To add the goal to your pom.xml, update the boost-maven-plugin entry in the pom.xml with the docker-build goal:

<plugin>
  <groupId>io.openliberty.boost</groupId>
  <artifactId>boost-maven-plugin</artifactId>
  <version>0.1</version>
  <executions>
    <execution>
      <goals>
        <goal>docker-build</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Run mvn clean package.

Running the Goal Directly

Alternatively, you can just run the goal directly:

Run mvn clean package

Run mvn boost:docker-build

Running the Docker image

Now that the Docker image is built, you can see the image in your local Docker registry.

Run docker images

Now run the application. The argument -p 9080:9080 maps the port opened inside the Docker container to a port in your operating system.

Run docker run -p 9080:9080 ${project.artifactId}

You can access the application on localhost:9080.

Pushing the Docker Image to a Registry

To push an image to a public or private registry, you need to configure the repository parameter in the format [REGISTRYHOST/][USERNAME/]NAME. The tag parameter is set to latest by default. You can do this either by adding an execution goal to the pom.xml or by running the goal directly in the terminal.

Updating the pom.xml

To add the goal to your pom.xml, update the plugin entry in the pom.xml:

<plugin>
  <groupId>io.openliberty.boost</groupId>
  <artifactId>boost-maven-plugin</artifactId>
  <version>0.1</version>
  <configuration>
    <repository>[your_domain_name]/${project.artifactId}</repository>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>docker-build</goal>
        <goal>docker-push</goal>
      </goals>
    </execution>
  </executions>
</plugin>

For a public registry like Docker Hub, replace [your_domain_name] with your Docker Hub username. For a private registry like IBM Container registry, replace [your_domain_name] with with your IBM Container Registry Host. You may need to include the namespace. For example, registry.ng.bluemix.net/test.

Update the Maven settings.xml file with your authentication details for the registry, for example:

  • For a public registry like Docker Hub:
    <server>
      <id>docker.io</id>
      <username>[your_registry_username]</username>
      <password>[your_registry_password]</password>
    </server>
  • For a private registry like IBM Container Registry:
    <server>
      <id>registry.ng.bluemix.net</id>
      <username>token</username>
      <password>[your_registry_token]</password>
    </server>

Run mvn clean install This creates a Docker image with the given repository name and the default tag latest, and then pushes the image to the registry.

Running the Goal Directly

Alternatively, to run the goal directly, first authenticate with the registry:

  • For a public registry like Docker Hub:
    docker login
  • For a private registry like IBM Container Registry:
    docker login -u token -p [your_registry_token] registry.ng.bluemix.net

Run mvn clean package

Run mvn boost:docker-build

Run mvn boost:docker-push

Try it Out!

Building efficient Docker images has never been so easy! Try the Boost Maven plugin to build and push efficient Docker images of your Spring Boot applications.

Just head over to the Sample app project and follow the instructions to build Liberty-based Docker images.

Docker (software) Spring Framework Spring Boot Build (game engine) push

Published at DZone with permission of Anjum Fatima, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top 12 Technical Skills Every Software Tester Must Have
  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It
  • DevOps Roadmap for 2022
  • Data Mesh vs. Data Fabric: A Tale of Two New Data Paradigms

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: