idea在docker環境,調試spring boot程序

容許docker被遠程訪問html

見:http://www.javashuo.com/article/p-gvzcttro-kw.htmljava

教程見:https://spring.io/guides/gs/spring-boot-docker/#initialweb


spring boot啓動類加上spring

@RestController

docker

@RequestMapping("/")
public String home() {
    return "Hello Docker!";
}

 

點擊idea右上的Edit Confgurations -> + -> Docker -> Dockerfile,配置如圖瀏覽器

 

點擊idea右上的Edit Confgurations -> + -> Remotetomcat

修改Name:xxxx Host:192.168.1.102 Port:45005 值根據本身的狀況來app

這時命令行參數變爲:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=45005dom

 

生成jar包socket

mvn clean package

 

項目根目錄建立Dockerfile

FROM openjdk:8-jdk-alpine
#WORKDIR /
VOLUME /tmp
EXPOSE 58080 5005
COPY /target/*.?ar /app/
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005","/app/docker-demo1-1.0.0.jar"]

 

項目根目錄建立docker-compose.yml 此步能夠省略

version: '3.4'
services:
  dockerweb:
    image: dockerdemox1:latest
    container_name: dockerdemox1
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./target:/app
    ports:
      - "48180:58080"

 

若沒有-Djava.security.egd=file:/dev/./urandom參數時,解決tomcat啓動慢的辦法

http://www.javashuo.com/article/p-ucwmojwh-eo.html

 

idea上經過docker啓動,自動生成鏡像和容器

再經過idea的remote啓動就能夠調試了。

 

在程序上打好端點,瀏覽器輸入192.168.1.102:48080

相關文章
相關標籤/搜索