Linux Docker部署SpringCloud

Linux Docker部署SpringCloud

  • 1 项目介绍
  • 2 快速部署
    • 2.1 api-registry
    • 2.1 api-gateway
    • 2.1 api-provider
    • 2.1 api-consumer

1 项目介绍

Linux Docker部署SpringCloud_第1张图片

        这是一个典型的springcloud项目架构,api-registry为注册中心,api-gateway为网关,api-provider为服务提供者,api-consumer为服务消费者,api-common为公共模块。

2 快速部署

        在Linux服务器上创建api-registry、api-gateway、api-provider、api-consumer目录,并分别上传jar包和Dockerfile文件至目录中。

mkdir /home/unified_user_service/api
cd /home/unified_user_service/api

mkdir api-registry
mkdir api-gateway
mkdir api-provider
mkdir api-consumer

2.1 api-registry

Dockerfile

FROM openjdk:15                                                     
WORKDIR /home                                                               
EXPOSE 6091
ENV LANG C.UTF-8
ENV TZ=Asia/Shanghai                                                         
ENTRYPOINT ["java", "-jar", "api-registry-1.0-SNAPSHOT.jar"]

构建镜像

docker build -t unified-user-service-api-registry .

运行容器

docker run --net=host --name unified-user-service-api-registry --restart=always -v /home/service/unified-user-service/api/api-registry:/home -d unified-user-service-api-registry

2.1 api-gateway

Dockerfile

FROM openjdk:15                                                     
WORKDIR /home                                                               
EXPOSE 6061
ENV LANG C.UTF-8
ENV TZ=Asia/Shanghai                                                         
ENTRYPOINT ["java", "-jar", "api-gateway-1.0-SNAPSHOT.jar"]

构建镜像

docker build -t unified-user-service-api-gateway .

运行容器

docker run --net=host --name unified-user-service-api-gateway --restart=always -v /home/service/unified-user-service/api/api-gateway:/home -d unified-user-service-api-gateway

2.1 api-provider

Dockerfile

FROM openjdk:15                                                     
WORKDIR /home                                                               
EXPOSE 6081
ENV LANG C.UTF-8
ENV TZ=Asia/Shanghai                                                         
ENTRYPOINT ["java", "-jar", "api-provider-1.0-SNAPSHOT.jar"]

构建镜像

docker build -t unified-user-service-api-provider .

运行容器

docker run --net=host --name unified-user-service-api-provider --restart=always -v /home/service/unified-user-service/api/api-provider:/home -d unified-user-service-api-provider

2.1 api-consumer

Dockerfile

FROM openjdk:15                                                     
WORKDIR /home                                                               
EXPOSE 6071
ENV LANG C.UTF-8
ENV TZ=Asia/Shanghai                                                         
ENTRYPOINT ["java", "-jar", "api-consumer-1.0-SNAPSHOT.jar"]

构建镜像

docker build -t unified-user-service-api-consumer .

运行容器

docker run --net=host --name unified-user-service-api-consumer --restart=always -v /home/unified_user_service/api/api-consumer:/home -d unified-user-service-api-consumer

你可能感兴趣的:(编程技术,linux,docker,spring,cloud)