标签:docke dock 文件解析 点击 完整 veth 活动 react dep
在面对复杂的分布式微服务应用时,传统的手工的基于物理机或虚拟机的部署方式效率低下且容易出错;Docker容器技术的出现,提供了一种可靠的打包和交付微服务的机制;另外向K8s这样的容器云平台的引入,可以进一步简化分布式微服务的部署和管理;通过K8s可以做到一键部署整个微服务应用,也可以一键扩容微服务应用;因此业界开始提出云原生Cloud Native架构理念,也就是说应用开发不仅要用微服务的方式组织架构,而且在架构上一开始就要考虑直接面向容器云环境部署。微服务架构和云原生架构相辅相成,微服务若离开了容器或容器云,部署和运维效率就会大打折扣
mappings:
-
name: faraday_route
host: faraday.staffjoy-v2.local
destinations: httpbin.org
-
name: account_route
host: account.staffjoy-v2.local
destinations: localhost:8081
-
name: company_route
host: company.staffjoy-v2.local
destinations: localhost:8082
-
name: ical_route
host: ical.staffjoy-v2.local
destinations: localhost:8083
-
name: whoami_route
host: whoami.staffjoy-v2.local
destinations: localhost:8084
timeout:
connect: 10000
read: 10000
-
name: superpowers_route
host: superpowers.staffjoy-v2.local
destinations: localhost:8085
-
name: www_route
host: www.staffjoy-v2.local
destinations: localhost:8086
-
name: myaccount_route
host: myaccount.staffjoy-v2.local
destinations: localhost:9000
-
name: app_route
host: app.staffjoy-v2.local
destinations: localhost:9001
127.0.0.1 account.staffjoy-v2.local
127.0.0.1 faraday.staffjoy-v2.local
127.0.0.1 myaccount.staffjoy-v2.local
127.0.0.1 whoami.staffjoy-v2.local
127.0.0.1 www.staffjoy-v2.local
127.0.0.1 ical.staffjoy-v2.local
127.0.0.1 staffjoy-v2.local
127.0.0.1 app.staffjoy-v2.local
127.0.0.1 company.staffjoy-v2.local
虚拟机 | |
Application | 容器 |
Bins/Libs | Application |
Guest OS | Bins/Libs |
Hypervisor | Minimal Guest OS |
Container Engine | |
Host OS | Host OS |
Hardware | Hardware |
Account服务Dockerfile
# 构建用基础镜像
FROM java:8-jdk-alpine
# 将maven build生成的jar包拷贝到镜像的/usr/app/目录下
COPY ./target/account-svc-1.0.0.jar /usr/app/
# 设置工作目录
WORKDIR /usr/app
RUN sh -c 'touch account-svc-1.0.0.jar'
# 容器启动后,如何运行account service
ENTRYPOINT ["java", "-jar", "account-svc-1.0.0.jar"]
# 构建用的基础镜像
FROM node:alpine as builder
# 设置工作目录
WORKDIR '/build'
# 将单页应用源代码、构建需要的资源、第三方依赖拷贝到镜像中
COPY myaccount ./myaccount
COPY resources ./resources
COPY third_party ./third_party
# 设置工作目录
WORKDIR '/build/myaccount'
# 构建:安装reactJs需要的依赖
RUN npm install
# 构建:构建node-sass
RUN npm rebuild node-sass
# 构建:生成静态html和js文件
RUN npm run build
RUN ls /build/myaccount/dist
# 换新的基础镜像
FROM nginx
# 暴露80端口
EXPOSE 80
# 把生成的builder资源拷贝到nginx镜像里
COPY --from=builder /build/myaccount/dist /usr/share/nginx/html
SPRING_PROFILES_ACTIVE=test
SERVER_PORT=80
EMAIL_SERVICE_ENDPOINT=http://email-service
COMPANY_SERVICE_ENDPOINT=http://company-service
ACCOUNT_SERVICE_ENDPOINT=http://account-service
BOT_SERVICE_ENDPOINT=http://bot-service
SMS_SERVICE_ENDPOINT=http://sms-service
SENTRY_DSN=https://80aaf4ae889b414f9fe72e3904cd5246@sentry.io/1380198
SIGNING_SECRET=secret
INTERCOM_ACCESS_TOKEN=YOUR_INTERCOM_ACCESS_TOKEN
INTERCOM_APP_ID=TBD
INTERCOM_SIGNING_SECRET=TBD
ALIYUN_ACCESS_KEY=YOUR_ALIYUN_ACCESS_KEY
ALIYUN_ACCESS_SECRET=YOUR_ALIYUN_ACCESS_SECRET
RECAPTCHA_PUBLIC=test-recaptcha-public
RECAPTCHA_PRIVATE=test-recaptcha-private
ACCOUNT_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/staffjoy_account?useUnicode=true&characterEncoding=utf-8
ACCOUNT_DATASOURCE_USERNAME=root
ACCOUNT_DATASOURCE_PASSWORD=root
COMPANY_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/staffjoy_company?useUnicode=true&characterEncoding=utf-8
COMPANY_DATASOURCE_USERNAME=root
COMPANY_DATASOURCE_PASSWORD=root
version: '3.7'
services:
account-service:
build: ./account-svc # dockerfile路径,用于做构建
image: boboweike/account-svc # 构建产生的镜像名称
environment: # 环境变量
- SPRING_PROFILES_ACTIVE
- SERVER_PORT
- SIGNING_SECRET
- SENTRY_DSN
- EMAIL_SERVICE_ENDPOINT
- COMPANY_SERVICE_ENDPOINT
- BOT_SERVICE_ENDPOINT
- INTERCOM_ACCESS_TOKEN
- ACCOUNT_DATASOURCE_URL
- ACCOUNT_DATASOURCE_USERNAME
- ACCOUNT_DATASOURCE_PASSWORD
depends_on: # 服务之间依赖的指定
- bot-service
- email-service
networks: # 网络配置
- internal_access
- external_access # db access
...
faraday-service:
build: ./faraday
image: boboweike/faraday-svc
ports:
- 80:80 # 不仅内部有80端口,还要向外暴露80端口
environment:
- SPRING_PROFILES_ACTIVE
- SERVER_PORT
- SENTRY_DSN
- SIGNING_SECRET
depends_on:
- account-service
- company-service
- www-service
- whoami-service
# - ical-service # commented for demo
- myaccount-service
- app-service
networks:
- internal_access
- external_access
myaccount-service:
build:
context: ./frontend
dockerfile: myaccount/Dockerfile
image: boboweike/myaccount-spa
networks:
- internal_access
...
networks:
internal_access:
internal: true
external_access:
download example
git clone https://github.com/docker/doodle.git
cd doodle\cheers2019
docker build -t wnzhong/cheers2019
docker run -it --rm wnzhong/cheers2019
docker login
docker push wnzhong/cheers2019
SpringBoot + Kubernetes云原生微服务实践 - (8) 服务容器化和Docker Compose部署
标签:docke dock 文件解析 点击 完整 veth 活动 react dep
原文地址:https://www.cnblogs.com/wnzhong/p/12186574.html