簡體   English   中英

如何使 Angular 和 Spring Boot 在 docker 內一起工作?

[英]How to make Angular and Spring Boot work together inside docker?

我在單獨的 Github 存儲庫中有我的 Angular 前端和 Spring 引導后端。 I am new to docker, I know how to build docker images for both separately and have also read about docker-compose to integrate the two, but having both the frontend and backend components in different repositories, I am not quite sure how to build a docker-compose that結合了前端和后端 docker 圖像。

假設您有一個angular:latest和一個spring-boot:latest docker 圖像,以及您的前端應用程序. /frontend . /frontend和后端在. /backend . /backend (那些是 git 存儲庫)

您可以使用 Docker compose 來創建您的部署:

version: '3.9'
services:
  frontend:
    image: angular:latest
    volumes:
       - ./frontend:/front
    command: <the right command to serve your app>
   ... [any other useful option, like ports, etc] 

  backend:
    image: spring-boot:latest
    volumes: 
       - ./backend:/back
    command: java -jar /back/target/your.jar #or something
   .. [any useful option]

優點:快速部署以進行測試,代碼正在go上更新

缺點:取決於您在目錄中放置的內容,它可能太多了,並且您失去了圖像的“包裝”感

其他解決方案:使用 Dockerfile 直接從 Github 創建 Docker 圖像並在圖像中復制應用程序的打包版本並啟動它。 您甚至可以使用 Github 操作來自動化它。

Docker 構建允許您從 Github 遠程上下文構建。您可以利用它。

優點:您將獲得一個打包在 docker 映像中的應用程序,該應用程序自給自足並可以自動部署

缺點:開發時不是最快的解決方案(但如果你做對了,你可能會從 CI/CD 管道中獲得質量平衡),學習曲線有點陡峭(但不是那么多)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM