Docker部署应用Dockfile文件和DockerCompose文件的Demo

  • docker-compose.yml
version: '3'

services:
    db:
        image: mysql
        environment: 
            - MYSQL_ROOT_PASSWORD=123456

        command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

        ports: 
            - "3306:3306"
        volumes:
            - ./mysql:/var/lib/mysql

    webDemo.migrator:
        image: xxxxxxxxxxx
        build:
            context: .
            dockerfile: src/services/demoService/src/DemoService.Migrator/Dockerfile
        volumes:
            - "./settings/migrator/appsettings.json:/app/appsettings.json"
        depends_on: 
            - db 
        links: 
            - db

    webDemo.host:
        image: xxxxxxxxxx/host
        environment:
            - ASPNETCORE_ENVIRONMENT=Staging
        build:
            context: .
            dockerfile: src/services/demoService/src/DemoService.Web.Host/Dockerfile
        ports:
            - "12360:80"
        volumes:
            - "./settings/host/appsettings.json:/app/appsettings.json"
            - "./settings/host/appsettings.Staging.json:/app/appsettings.Staging.json"
        depends_on: 
            - db 
        links: 
            - db
            
    webDemo.web:
        image: xxxxxxxxxx/web
        build:
            context: .
            dockerfile: src/web/Dockerfile
        ports:
            - "80:80"
        volumes:
            - "./settings/web/appconfig.json:/usr/share/nginx/html/assets/appconfig.json"
            - "./settings/web/nginx.conf:/etc/nginx/nginx.conf"
            - "./settings/web/outputs/:/web/dist/"


  • Migrator,迁移数据库的Dockerfile
FROM microsoft/dotnet:latest AS publish
WORKDIR /src
COPY ./src/DemoService/ .
WORKDIR ./src/DemoService.Migrator
RUN dotnet restore
RUN dotnet publish -c Release -o /app
COPY . .

FROM publish AS final
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "DemoService.Migrator.dll"]
  • WebHost
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ./src .
WORKDIR ./src/DemoService.Web.Host
RUN dotnet restore
RUN dotnet publish -c Release -o /app

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS publish
WORKDIR /app

FROM publish AS final
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "DemoService.Web.Host.dll"]
  • WEB Dockerfile
FROM node AS builder
WORKDIR /web
COPY ./src/Web/DemoWeb .
RUN npm i
RUN npm run build

FROM nginx AS final
WORKDIR /usr/share/nginx/html
COPY --from=builder ./web/dist/. /usr/share/nginx/html
COPY --from=builder ./web/nginx.conf /etc/nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值