這是我的Dockerfile,但是如果我改了java代碼,然後輸入「docker-compose up -d --build」到終端,maven會重新下載jar,如何避免重複下載?如何在開發環境中使用maven-docker以避免重複下載jar?
Dockerfile:
FROM maven:3.5.0-jdk-8
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn verify
ENTRYPOINT ["java","-jar","target/cloud-user.jar"]
泊塢窗,compose.yml:
version: "2"
services:
cloud-nginx:
build: cloud-nginx
image: registry.cn-beijing.aliyuncs.com/wangdali/cloud-nginx
restart: always
ports: ["80:80"]
cloud-consul:
image: consul:0.9.2
command: consul agent -dev -client 0.0.0.0
cloud-front:
build: cloud-front
image: registry.cn-beijing.aliyuncs.com/wangdali/cloud-front
restart: always
volumes:
- ./cloud-front/static:/app
cloud-user:
build: cloud-user
image: registry.cn-beijing.aliyuncs.com/wangdali/cloud-user
restart: always
mysql:
image: mysql:5.7.19
hostname: mysql
volumes:
- ./docker/mysql/data:/var/lib/mysql
- ./docker/mysql/conf:/etc/mysql/conf.d
- /etc/localtime:/etc/localtime
ulimits:
nproc: 65535
mem_limit: 1024m
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
我簡化我的測試項目,然後用彈簧啓動插件行家
mvn spring-boot:運行
要啓動項目,現在先掛載.m2文件夾,然後運行mvn命令。 但是我更改了java源代碼後,它不會自動加載devtools,如何解決?
,這是我Dockerfile /泊塢窗-compose.yml:
Dockerfile:
version: "2"
services:
user:
build: user
volumes:
- $HOME/.m2/repository:/root/.m2/repository
- ./user/src:/app/src
ports:
- "8080:8080"
泊塢窗,compose.yml:
FROM maven:3.5.0-jdk-8
WORKDIR /app
COPY pom.xml .
COPY src ./src
ENTRYPOINT ["mvn","spring-boot:run"]
登上當地CACH'$ HOME/.m2目錄/ repository'到您的碼頭工人圖像......但是你爲什麼在Docker容器內部構建?爲什麼不簡單地通過Dockerfile將最終生成的war/jar文件複製到Docker容器中? – khmarbaise
@khmarbaise最初,我想添加jar並在容器中運行它,但代碼在開發過程中更頻繁地更改,而且這個過程似乎過於繁瑣。然後我想將$ HOME/.m2/repository作爲數據卷放在容器中,但我嘗試了很多次,並沒有弄清楚如何在執行mvn verify之前將.m2目錄掛載到容器中。 –
@khmarbaise非常感謝你 –