Coder Social home page Coder Social logo

create-boot-dockerfile's Introduction

containerizing spring boot application

two ways: from a Dockerfile or a Springboot Maven plugin

Creating Dockerfile

A SpringBoot application Image bases on an OpenJDK image because Java has been deprecated.

The name, Dockerfile, is a unique name for a docker file, and it starts with a capital D, and the rest are small.

It may need to simplify a jar file name within a Maven build section

<build>
		<finalName>welcome-docker</finalName>
</build>

SpringBoot web application by default exposes itself to the port 8080 of the container and overriding the EXPOSE in the docker file. This may cause the port not correctly mapped, and cannot be accessed from the client-side.

It may need to explicitly define sever port within the application.properties.

Within application.properties, we may explicitly define SpringBoot exposure port. 
server.port=8085

And remapping to the host port.
docker run -p 8085:8085 spring-boot-welcome-web

Build docker image

The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL.

docker build [OPTIONS] PATH | URL | -

docker build -f PATH/Dockerfile -t name:tag PATH

[OPTIONS]
-f: Name of the Dockerfile (Default is 'PATH/Dockerfile')
-t: Name and optionally a tag in the 'name:tag' format

docker build -t spring-boot-welcome-web:latest .

. stands for the current path

Run customer image

docker run -p 8085:8085 spring-boot-welcome-web

Enter inside container

docker exec -it container-name/container-id bash

run command env 

image

The target jar file was ADDed inside container root directory.

From Springboot Maven Plugin

mvn spring-boot:build-image

image

create-boot-dockerfile's People

Contributors

yichunzhao avatar

Watchers

 avatar  avatar

Forkers

vindhyajee5

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.