Docker部署应用Dockfile文件和DockerCompose文件的Demo
程序员文章站
2022-03-07 23:19:49
...
- 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