Giter Site home page Giter Site logo

motaharinia / springboot-docker Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 56 KB

spring-boot with docker. process of building a Docker image for running a Spring Boot application

Home Page: https://www.linkedin.com/in/motaharinia/

Dockerfile 16.01% Java 83.99%
spring-boot docker docker-images docker-file expose entrypoint maven dockerbuild dockerimages dockerrun

springboot-docker's Introduction

Spring Boot with Docker

Docker

Developing apps today requires so much more than writing code. Multiple languages, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage creates enormous complexity. Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.

Docker Images:

https://hub.docker.com/search?q=&type=image

further references:

Project Descriptions :

please see application.properties files in resources folder and select a active profile "dev" or "com" to run project. you can check test methods too.
docker configuration steps:

  1. install docker desktop for windows from "https://hub.docker.com/editions/community/docker-ce-desktop-windows"

    • login with docker id and password
    • click on docker tray icon and uncheck the "setting/general/start docker desktop when you log in" (because of vpn should be run before)
    • click on docker tray icon and uncheck the "setting/general/automatically check for update" (because of vpn should be run before)
    • click on docker tray icon and check the "setting/general/expose daemon on tcp://localhost:2375 without tls" and restart docker (to use in intellij docker window)
    • click on docker tray icon and goto "setting/resources/advanced/disc image location" you can change image location
  2. current project is created as below:

    • Java: 13
    • Artifact: dockertest
    • Packaging: jar
    • Dependencies: "Spring web"
    • in application.properties added:
      • server.port=8080
    • in pom.xml inside tag added below tag:
      • <finalName>dockertest</finalName>
  3. added "Dockerfile" file beside "pom.xml" with these lines:
    FROM openjdk:13
    ADD target/dockertest.jar dockertest.jar
    EXPOSE 8080
    ENTRYPOINT ["java", "-jar", "dockertest.jar"]

  4. in IntelliJ IDEA , select lifecycle/clean and lifecycle/install and run in maven box to create jar file in target:

  5. in IntelliJ IDEA terminal in project folder

    • check current terminal path:
      cd

    • check docker version:
      docker -v

    • build docker image file from "Dockerfile" properties in project beside pom.xml with tag "dockertest" (it will download openjdk image file for the first time):
      docker build -f Dockerfile -t dockertest .

    • check docker images after build:
      docker images

    • push and run docker image for test spring application with same port 8080 in spring(we can change docker port as we wish):
      docker run -p 8080:8080 dockertest

    • check terminal commands history:
      history

    • clear terminal:
      cls

  6. test spring boot application on windows Browser: http://localhost:8080

  7. in IntelliJ IDEA in the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Docker. Click The Add button to add a Docker configuration and specify how to connect to the Docker daemon.

    • Name: MyDocker
    • Connect to Docker daemon with: select TCP socket on "tcp://localhost:2375" (Path Mapping: For Windows and macOS: Specify the mappings for folders that can be shared between the host and the container volumes)
  8. be carefull of huge log file in c:\users\MyUser.intellijidea2019.3\system\log\docker.log after apply this setting for IntelliJ IDEA

  9. in IntelliJ IDEA "view menu/tool window/services" we can see docker and connect to it

  10. stop container by id: "docker exec stop". copy docker image from "docker images" command. for example:
    docker exec db79a8e5fdae stop

IntellliJ IDEA Configurations :

  • IntelijIDEA: Help -> Edit Custom Vm Options -> add these two line:
    • -Dfile.encoding=UTF-8
    • -Dconsole.encoding=UTF-8
  • IntelijIDEA: File -> Settings -> Editor -> File Encodings-> Project Encoding: form "System default" to UTF-8. May be it affected somehow.
  • IntelijIDEA: File -> Settings -> Editor -> General -> Code Completion -> check "show the documentation popup in 500 ms"
  • IntelijIDEA: File -> Settings -> Editor -> General -> Auto Import -> check "Optimize imports on the fly (for current project)"
  • IntelijIDEA: File -> Settings -> Editor -> Color Scheme -> Color Scheme Font -> Scheme: Default -> uncheck "Show only monospaced fonts" and set font to "Tahoma"
  • IntelijIDEA: Run -> Edit Configuration -> Spring Boot -> XXXApplication -> Configuration -> Environment -> VM Options: -Dspring.profiles.active=dev
  • IntelijIDEA: Run -> Edit Configuration -> Spring Boot -> XXXApplication -> Code Coverage -> Fix the package in include box

springboot-docker's People

Contributors

motaharinia avatar

Watchers

 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.