Code Monkey home page Code Monkey logo

docker_boot's Introduction

Docker and Spring boot seed project

##Assumptions:

  1. You have basic knowledge of spring profiling.
  2. Docker is installed on your system.
  3. for Amazon's ECS:
    1. aws cli is installed on your system
    2. You have amazon secret key and access key with you, if generate your credentials.
    3. you have ECR access for your user.

To pull this docker image use

docker pull javatechy/dockboot

Dockerizing your spring boot application

  • To Dockerize a spring boot application create a folder docker inside src/main/
  • Copy Dockerfile and wrapper.sh from src/main/docker of this project into your project's src/main/docker
  • Add this repository path in your pom properties(in your project or in your pom/ if your are using parent pom add it there).

If you are using Amazon ECR add your registry like this:

	<docker.registry>XXXXXXXX.dkr.ecr.ap-south-1.amazonaws.com</docker.registry>

If you want to push the image in your public docker hub account add your username like this

	<docker.registry>javatechy</docker.registry>
  • Add this plugin in plugins section of your pom.xml
  <plugin>
   			<groupId>io.fabric8</groupId>
   			<artifactId>docker-maven-plugin</artifactId>
   			<configuration>
   				<verbose>true</verbose>
   				<registry>${docker.registry}</registry>
   				<dockerFileDir>src/main/docker</dockerFileDir>
   				<images>
   					<image>
   						<name>${docker.registry}/dockboot:${project.version}</name>
   						<build>
   							<dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
   							<tags>
   								<tag>${project.version}</tag>
   								<tag>latest</tag>
   							</tags>

   							<assembly>
   								<inline>
   									<dependencySets>
   										<dependencySet>
   											<includes>
   												<include>${project.groupId}:${project.artifactId}</include>
   											</includes>
   											<outputFileNameMapping>app.jar</outputFileNameMapping>
   										</dependencySet>
   									</dependencySets>
   								</inline>
   							</assembly>
   						</build>
   					</image>
   				</images>
   			</configuration>
   			<executions>
   				<execution>
   					<id>build-docker-image</id>
   					<phase>package</phase>
   					<goals>
   						<goal>build</goal>
   					</goals>
   				</execution>
   				<execution>
   					<id>push-docker-image</id>
   					<phase>deploy</phase>
   					<goals>
   						<goal>push</goal>
   					</goals>
   				</execution>
   			</executions>
   		</plugin>

Note: replace dockboot in above code inside images->image->name with your application name.

Build your docker image:

Run this command and your will find your docker image in docker images
mvn clean install
to Skip docker build
mvn clean install -Ddocker.skip

Push An Image to ECR:

  • Configure your aws cli using this command aws configure and add your credentials and region.
  • get Login credentials from ECS by using this
aws ecr get-login --no-include-email --region ap-south-1
  • If your project's repository is not created yet execute this command aws ecr create-repository --repository-name PROJECT_NAME

  • Copy the above command output and run it.

  • check your image after mvn clean install using docker images

  • To Push an image ,Go inside your project directory. (If using mutlimodule project go inside your working project directory or sub project) and execute this command

mvn docker:push

Run this image:

Assuming your logs directory /var/log/casa and your spring boot active profile is DEV provided by ENV_NAME

docker run -it -v /var/log/casa:/var/log/casa -p 9000:8000 -e ENV_NAME=dev javatechy/dockboot:1.0

Run in detached Mode

docker run -it -v /var/log/casa:/var/log/casa -p 9000:8000 -d -e ENV_NAME=dev javatechy/dockboot:1.0

docker_boot's People

Contributors

javatechy avatar

Watchers

 avatar

docker_boot's Issues

A annotation misuse

In the file of "src/main/java/javatechy/dockboot/service/MyService.java", this is an annotation misuse, we hold the view that changing annotation from @component to @service is more appropriate here.

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.