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. Software Design and Architecture
  3. Cloud Architecture
  4. Build Images and Run Docker Containers in Maven

Build Images and Run Docker Containers in Maven

Learn how to use a new Maven plugin to help test Java applications in containers without having to use the error-prone Docker command line.

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
Sep. 25, 15 · Tutorial
Like (4)
Save
Tweet
Share
13.03K Views

Join the DZone community and get the full member experience.

Join For Free

In order for Java developers to test their applications in containers they typically have to build their code, create an image, and run a container. You can use the Docker command line interface to manage images and containers, but at least for me that's often error-prone and I have to go back to my cheatsheet to find the right commands. I tried a Docker Maven plugin instead and my initial experience is very positive.

There are actually several Maven plugins for Docker. Roland Huß wrote a nice high level comparison where he explains why he created another plugin. I tried the Spotify one briefly but that one doesn't allow running containers. The plugin from Roland rhuss/docker-maven-plugin seems very promising. Below I used it for my simple Java sample.


With the plugin you can build images and run containers and also easily remove these again which is especially important in the iterative development phase.

Build Image:

> mvn docker:build

Run Container:

> mvn docker:start

Stop and Remove Container:

> mvn docker:stop

Remove Image:

> mvn -Ddocker.removeAll docker:remove

The plugin also supports to push images to other registries but I haven't tried it yet. To find out more read the Intro and the Manual. 

Docker (software) Build (game engine) Apache Maven

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Quest for REST
  • Upgrade Guide To Spring Data Elasticsearch 5.0
  • Load Balancing Pattern
  • How to Create a Real-Time Scalable Streaming App Using Apache NiFi, Apache Pulsar, and Apache Flink SQL

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: