Git Product home page Git Product logo

spring-boot-docker's Introduction

spring-boot-docker

How to build a docker image for running a spring boot application using the dockerfile-maven-plugin from Spotify, with Docker Toolbox.

We need to have a Dockerfile — for the purpose of demonstration there’s a Dockerfile. Add Dockerfile into our root directory alongside our pom.xml.

Dockerfile

Start with a base image containing Java runtime

FROM dperezcabrera/openjdk11-alpine

Add Maintainer Info

MAINTAINER Zeeshan Alam Khan [email protected]

Add a volume pointing to /tmp

VOLUME /tmp

Make port 8080 available to the world outside this container

EXPOSE 8080

The application's jar file

ARG JAR_FILE=target/docker-example.jar

Add the application's jar to the container

ADD ${JAR_FILE} docker-example.jar

Run the jar file

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/docker-example.jar"]

Next we will add some configuration into the pom.xml, specifically repository tag and an argument for the JAR_FILE which you can see we reference in the Dockerfile above.

spotify dockerfile maven plugin

 <plugin>
			<groupId>com.spotify</groupId>
			<artifactId>dockerfile-maven-plugin</artifactId>
			<version>1.4.13</version>
			<configuration>
				<repository>zeeshanalamkhan/docker-example</repository>
				<tag>${project.version}</tag>
				<dockerHost>https://192.168.99.100:2376</dockerHost>
				<dockerCertPath>C:/Users/<Your User name>/.docker/machine/machines/default
				</dockerCertPath>
				<buildArgs>
					<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
				</buildArgs>
			</configuration>
			<executions>
				<execution>
					<id>default</id>
					<phase>install</phase>
					<goals>
						<goal>build</goal>
						<goal>push</goal>
					</goals>
				</execution>
			</executions>
		</plugin>

Now run the project as maven build ->goal -> clean package dockerfile:build On completion we should see a message indicating the Docker image has been successfully created.

Once built, we can run our new Docker image as. docker run -p 8080:8080 docker-example:0.0.1-SNAPSHOT

and we can access our application from web browser or postman as 192.168.99.102:8080/hello/{any name}

spring-boot-docker's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.