通過 docker-compose 一鍵部署一個微服務專案
強推文章:
打包,移包
-
進入到專案根目錄,通過 mvn clean test package install 生成 jar/war 包。
-
在 target 目錄內,找到打包好的 jar 包 / war 包。複製到 Linux 系統的指定目錄
把 jar包放入對應的目錄內,以下是放好jar包的目錄結構。
[root@localhost supershop]# tree
.
├── docker-compose
│ ├── service
│ │ └── docker-compose.yml
│ └── web
│ └── docker-compose.yml
├── supershop-service-admin
│ ├── Dockerfile
│ └── supershop-service-admin.jar
├── supershop-service-portal
│ ├── Dockerfile
│ └── supershop-service-portal.jar
├── supershop-service-redis
│ ├── Dockerfile
│ └── supershop-service-redis.jar
├── supershop-web-admin
│ ├── Dockerfile
│ └── supershop-web-admin.jar
└── supershop-web-portal
├── Dockerfile
└── supershop-web-portal.jar
7 directories, 12 files
[root@localhost supershop]#
編寫 Dockerfile
supershop-service-admin 目錄內的 Dockerfile
[root@localhost supershop]# cat ./supershop-service-admin/Dockerfile
FROM openjdk:8-jre
MAINTAINER Flying <814110433@qq.com>
RUN mkdir /app
WORKDIR /app
COPY supershop-service-admin.jar /app
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/supershop-service-admin.jar"]
EXPOSE 20880 8510
[root@localhost supershop]#
supershop-web-admin 目錄內的 Dockerfile
[root@localhost supershop]# cat ./supershop-web-admin/Dockerfile
FROM openjdk:8-jre
MAINTAINER Flying <814110433@qq.com>
RUN mkdir /app
WORKDIR /app
COPY supershop-web-admin.jar /app
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/supershop-web-admin.jar"]
EXPOSE 8100
[root@localhost supershop]#
supershop-service-redis 目錄內的 Dockerfile
[root@localhost supershop]# cat ./supershop-service-redis/Dockerfile
FROM openjdk:8-jre
MAINTAINER Flying <814110433@qq.com>
RUN mkdir /app
WORKDIR /app
COPY supershop-service-redis.jar /app
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/supershop-service-redis.jar"]
EXPOSE 20882 8512
[root@localhost supershop]#
編寫 docker-compose.yml
根據啟動先後順序和服務型別配置一個或多個 docker-compose.yml 。此處分為 service 和 web 。先啟動 service ,再啟動 web 。
存放 docker-compose.yml 的目錄
[root@localhost docker-compose]# tree
├── service
│ └── docker-compose.yml
└── web
└── docker-compose.yml
2 directories, 2 files
[root@localhost docker-compose]# pwd
/root/supershop/docker-compose
[root@localhost docker-compose]# ls
service web
[root@localhost docker-compose]#
service 的 docker-compose 內容
[root@localhost docker-compose]# cd service/
[root@localhost service]#
[root@localhost service]# ls
docker-compose.yml
[root@localhost service]#
[root@localhost service]# cat docker-compose.yml # service 的 docker-compose 內容
version: '3'
services:
supershop-service-redis:
build:
context: ../../supershop-service-redis
dockerfile: Dockerfile
image: supershop-service-redis:latest
container_name: supershop-service-redis
ports:
- 20882:20882
- 8512:8512
networks:
supershop_net:
aliases:
- supershop-service-redis
restart: always
healthcheck:
test: "/bin/netstat -anpt|grep 8512"
interval: 30s
timeout: 3s
retries: 1
supershop-service-admin:
build:
context: ../../supershop-service-admin
dockerfile: Dockerfile
image: supershop-service-admin:latest
container_name: supershop-service-admin
ports:
- 20880:20880
- 8510:8510
networks:
supershop_net:
aliases:
- supershop-service-admin
restart: always
depends_on:
- "supershop-service-redis"
healthcheck:
test: "/bin/netstat -anpt|grep 8510"
interval: 30s
timeout: 3s
retries: 1
supershop-service-portal:
build:
context: ../../supershop-service-portal
dockerfile: Dockerfile
image: supershop-service-portal:latest
container_name: supershop-service-portal
ports:
- 20881:20881
- 8511:8511
networks:
supershop_net:
aliases:
- supershop-service-portal
restart: always
depends_on:
- "supershop-service-redis"
healthcheck:
test: "/bin/netstat -anpt|grep 8511"
interval: 30s
timeout: 3s
retries: 1
networks:
supershop_net:
external: true
[root@localhost service]#
web 的 docker-compose 內容
[root@localhost service]# cd ../web/ && ll && cat docker-compose.yml # web 的 docker-compose 內容
總用量 4
-rwxr-xr-x. 1 root root 1010 9月 27 00:06 docker-compose.yml
version: '3'
services:
supershop-web-admin:
build:
context: ../../supershop-web-admin
dockerfile: Dockerfile
image: supershop-web-admin:latest
container_name: supershop-web-admin
ports:
- 8100:8100
networks:
supershop_net:
aliases:
- supershop-web-admin
restart: always
healthcheck:
test: "/bin/netstat -anpt|grep 8100"
interval: 30s
timeout: 3s
retries: 1
supershop-web-portal:
build:
context: ../../supershop-web-portal
dockerfile: Dockerfile
image: supershop-web-portal:latest
container_name: supershop-web-portal
ports:
- 8101:8101
networks:
supershop_net:
aliases:
- supershop-web-portal
restart: always
healthcheck:
test: "/bin/netstat -anpt|grep 8101"
interval: 30s
timeout: 3s
retries: 1
networks:
supershop_net:
external: true
[root@localhost web]#
啟動
先進入 service 目錄: docker-compose build && docker-compose up -d
再進入 web 目錄: docker-compose build && docker-compose up -d
待解決的問題?
- npm run dev 如何在 Linux 上執行?
- npm run dev 如何在 Linux 上持久執行?
- 多個 npm run dev 如何在 Linux 上持久執行?
相關文章
- docker-compose一鍵部署java開源專案DockerJava
- 利用docker-compose一鍵部署Docker
- docker(二十三):docker通過docker-compose部署redmine服務Docker
- SpringCloud微服務專案搭建與部署教程SpringGCCloud微服務
- 通過VuePress管理專案文件(一)Vue
- 微服務不過只是一個新名頭微服務
- 如何打包部署一個tomcat專案Tomcat
- Knative 實戰:一個微服務應用的部署微服務
- IDEA一鍵部署SpringBoot專案到伺服器IdeaSpring Boot伺服器
- 使用docker-compose執行微服務專案#eureka+config+auth+gateway+moduleDocker微服務Gateway
- 十一、Docker搭建部署SpringCloud微服務專案DemoDockerSpringGCCloud微服務
- docker-compose 部署 Laravel 專案全記錄DockerLaravel
- 通過tomcat的ManagerServlet遠端部署專案TomcatServlet
- 通過GitHub Action自動部署Maven專案GithubMaven
- Dubbo 入門系列之快速部署一個微服務應用微服務
- 透過skaffold快速部署微服務微服務
- Eclipse通過EGit外掛提交多個專案到同一個倉庫EclipseGit
- Spring Cloud之微服務之間相互呼叫、如何讓一個微服務呼叫另外一個微服務SpringCloud微服務
- 通過express快速搭建一個node服務Express
- Serverless與微服務探索(二)- SpringBoot專案部署實踐Server微服務Spring Boot
- Spring Cloud 微服務專案實現總架構一SpringCloud微服務架構
- shell——一鍵部署服務實戰
- 微服務之間通過RabbitMQ通訊微服務MQ
- Azure DevOps (十二) 通過Azure Devops部署一個SpringBoot應用devSpring Boot
- Azure DevOps (十一) 通過Azure Devops部署一個.NET Core WebAPIdevWebAPI
- .Net Core微服務入門全紀錄(一)——專案搭建微服務
- 從程式碼到部署微服務實戰(一)微服務
- RecyclerView 結合cardview和materia degisn通過retrofit的一個專案,山寨it之家View
- uwsgi + nginx 部署python專案(一)NginxPython
- 使用docker-compose 一鍵部署你的分散式呼叫鏈跟蹤框架skywalkingDocker分散式框架
- docker-compose + nginx部署前後端分離的專案DockerNginx後端
- docker-compose一鍵部署redis一主二從三哨兵模式(含密碼,資料持久化)DockerRedis模式密碼持久化
- 微服務專案實踐之中建專案微服務
- Azure Service Fabric Mesh:一個構建任務關鍵型微服務的平臺微服務
- 微服務部署微服務
- [譯] 用 Rust 寫一個微服務Rust微服務
- 編寫第一個 .NET 微服務微服務
- Docusaurus 一鍵快速部署個人部落格