All Projects → indrabasak → Docker Example

indrabasak / Docker Example

Example Spring Boot Application with Docker

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Docker Example

Search Spring Boot Starter
ElasticSearch封装基于ES版本6.4.2,极大简化了ES操作难度
Stars: ✭ 23 (+109.09%)
Mutual labels:  spring-boot
Blocklang.com
软件拼装工厂/低代码平台
Stars: ✭ 26 (+136.36%)
Mutual labels:  spring-boot
E2e Experiment
A demo project with Spring Boot / Angular application and e2e tests
Stars: ✭ 9 (-18.18%)
Mutual labels:  spring-boot
Spring Postgresql Demo
Spring Boot 2.0 application, backed by PostgreSQL, and designed for deployment to Pivotal Cloud Foundry (PCF)
Stars: ✭ 23 (+109.09%)
Mutual labels:  spring-boot
Micro Server
Microserver is a Java 8 native, zero configuration, standards based, battle hardened library to run Java Rest Microservices via a standard Java main class. Supporting pure Microservice or Micro-monolith styles.
Stars: ✭ 929 (+8345.45%)
Mutual labels:  spring-boot
Ecommerceapp
QA Strategy for microservices with Synchronous and Asynchronous communication
Stars: ✭ 27 (+145.45%)
Mutual labels:  spring-boot
Mart Holiday Alarm
🛒 마트쉬는날 🏖
Stars: ✭ 22 (+100%)
Mutual labels:  spring-boot
Hello Sso Jwt Resource
Single Sign On (SSO) Example with JSON Web Token (JWT), Spring Boot
Stars: ✭ 10 (-9.09%)
Mutual labels:  spring-boot
Subnode.org
SubNode: Social Media App
Stars: ✭ 25 (+127.27%)
Mutual labels:  spring-boot
Springbootunity
rabbitmq、redis、scheduled、socket、mongodb、Swagger2、spring data jpa、Thymeleaf、freemarker etc. (muti module spring boot project) (with spring boot framework,different bussiness scence with different technology。)
Stars: ✭ 845 (+7581.82%)
Mutual labels:  spring-boot
Spring Qrcode Example
Demonstrates some of the capabilities of the Spring Boot framework through a small, simple example.
Stars: ✭ 23 (+109.09%)
Mutual labels:  spring-boot
Sample Camel Spring Boot
three samples in different branches that illustrates usage of apache camel as microservice framework providing integration with consul, hystrix, ribbon and other tools
Stars: ✭ 24 (+118.18%)
Mutual labels:  spring-boot
Spring Boot Elasticsearch Lire Docker
Spring-boot+ElasticSearch+LIRE+SwaggerUI RESTful.
Stars: ✭ 7 (-36.36%)
Mutual labels:  spring-boot
Httpdoc
基于Java标准doc注释构建的代码零侵入的HTTP RESTful API在线测试,文档阅览以及SDK导出框架,支持Spring-Boot和Spring-MVC
Stars: ✭ 23 (+109.09%)
Mutual labels:  spring-boot
Versionmonitor
Monitors different kinds of software projects for new releases
Stars: ✭ 9 (-18.18%)
Mutual labels:  spring-boot
Localstack Spring Boot
Spring Boot AutoConfiguration for LocalStack
Stars: ✭ 22 (+100%)
Mutual labels:  spring-boot
Spring Boot Web Nashorn
Feasibility of rendering React 16.x templates from Nashorn with babel-standalone, with Spring Boot and Kotlin
Stars: ✭ 26 (+136.36%)
Mutual labels:  spring-boot
Versioning Spring Boot Starter
Spring boot starter using for versioning rest easily.
Stars: ✭ 11 (+0%)
Mutual labels:  spring-boot
Spring Boot Rest Api Example
Implement REST APIs using Spring Boot and Spring Session.
Stars: ✭ 10 (-9.09%)
Mutual labels:  spring-boot
Newbee Mall Vue App
Vue2 全家桶 + Vant 搭建大型单页面商城项目。新蜂商城前后端分离版本-前端Vue项目源码
Stars: ✭ 836 (+7500%)
Mutual labels:  spring-boot

Build Status

Spring Boot Example with Docker

This example creates a Docker image from a Spring Boot application using Spotify's Docker Maven plugin.

Modules

The project consist of two modules:

  1. docker-example-model - contains all the models used in the example
  2. docker-spring-service - contains Spring Boot example service and related classes

Build and Run

Maven Build

Make sure you have Maven installed. Execute the following maven command from the directory of the parent project, docker-example:

mvn clean install

It will create the Spring Boot executable JAR,docker-example-service-1.0.jar, under docker-example-service/target folder.

Run

To run the newly created Spring Boot JAR from the terminal:

java -jar docker-example-service-1.0.jar

This should start up the example application at port 8080. The application can be accessed at http://localhost:8080

Docker Build

Before you build the Docker image, make sure Docker is available in your environment. Execute the following maven command from the directory of the parent project, docker-example:

mvn clean package docker:build

This should build a Docker image named docker-example.

Docker Run

Run the newly created Docker image, docker-example, by executing the docker run command from the terminal:

docker run --rm -p 8080:8080  --name=cheetos docker-example
Options
  • --rm option automatically clean up the container and remove the file system when the container exit.
  • --name option names the Docker container as cheetos. In absence of the --name option, the Docker generates a random name for your container.
  • -p 8080:8080 option publishes all exposed ports to the host interfaces. In our example, it is port 8080 is both hostPort and containerPort

This should start up the example application and it can be accessed at http://localhost:8080

Docker Commands

List Container

Run the docker ps to list all the containers. To see all running containers, execute the following command:

bash-3.2$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
d03854fb7779        docker-example      "java -Djava.security"   7 seconds ago       Up 6 seconds        0.0.0.0:8080->8080/tcp   cheetos
bash-3.2$ 

To see all running containers including the non-running ones, execute the following command:

bash-3.2$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                         PORTS                    NAMES
d03854fb7779        docker-example      "java -Djava.security"   About a minute ago   Up About a minute              0.0.0.0:8080->8080/tcp   cheetos
28b2cff9e7e6        docker-example      "java -Djava.security"   About an hour ago    Exited (0) About an hour ago                            indra1
d2720676c932        nginx               "nginx -g 'daemon off"   4 months ago         Exited (0) 4 months ago                                 webserver

Remove Container

To remove a Docker container, execute docker rm command. This will remove a non-running container.

bash-3.2$ docker rm indra1
indra1 

To forcefully remove a running container

bash-3.2$ docker rm -f cheetos
cheetos

Stop Container

To stop a container, execute docker stop

command:
bash-3.2$ docker stop cheetos
cheetos

Docker Maven Plugin Setup

We are using Spotify's Docker Maven Plugin. It's relatively easy to setup in your Maven pom.xml. Complexity rises when you specify the plugin in the parent POM. Here are the changes to the parent pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.13</version>
                <configuration>
                    <skipDockerBuild>true</skipDockerBuild>
                </configuration>
            </plugin>
        </plugins>
    </build>

The skipDockerBuild tag is set to true in order to skip the docker build in the parent pom.

Changes to the child pom.xml where Spring Boot JAR gets created:

    <build>
        <plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <skipDockerBuild>false</skipDockerBuild>
                    <imageName>${docker.image.name}</imageName>
                    <dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
    </build>

Here is the skipDockerBuild tag is set to false to override the parent flag.

Configuration Tags
  • imageName specifies the name of our example Docker image, e.g, docker-example
  • dockerDirectory specifies the location of the Dockerfile. The contents of the dockerDirectory will be copied into ${project.build.directory}/docker. A Dockerfile specfies all the instructions to be read by Docker while building the image.
  • include specfies the resources to be included, which ion our case is docker-example-service-1.0.jar

DockerFile

Here is the content of the example Dockerfile.

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD docker-example-service-1.0.jar app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 8080
ENV JAVA_OPTS=""
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-Dapp.port=${app.port}", "-jar","/app.jar"]
LABEL maintainer "Indra Basak"

Instruction

  • FROM instruction sets the Base Image for subsequent instructions. FROM must be the first non-comment instruction in the Dockerfile.
  • VOLUME instruction creates a mount point with the specified name.
  • ADD instruction copies from <src> and adds them to the filesystem of the image at the path <dest>.
  • RUN instruction executes the command on top of the current image.
  • EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
  • ENV instruction sets the environment variable
  • ENTRYPOINT allows you to configure a container that will run as an executable.
  • LABEL instruction adds metadata to an image.

You can find out more about Docker instructions here

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].