Asp .Net Core 系列:Asp .Net Core 3.1+MySQL 部署到 docker 上面(docker-compose+DockerFile方式)
一.新建DockerFile文件
选择Linux版本
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /code COPY *.csproj ./ RUN dotnet restore COPY . ./ RUN dotnet publish -c Release -o out FROM base AS final WORKDIR /app COPY --from=build /code/out ./ ENTRYPOINT ["dotnet", "DockerDemo.dll"]
二新建docker-compose.yml文件
version: '3.4' services: db: image: mysql/mysql-server:5.7 container_name: mysql command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci restart: always ports: - '3306:3306' environment: MYSQL_ROOT_PASSWORD:password MYSQL_USER: robin MYSQL_PASSWORD:password volumes: - /d/data:/docker-entrypoint-initdb.d web: build: context: . dockerfile: DockerFile container_name: core ports: - '8802:80' depends_on: - mysql
三.执行命令:docker-compose build
四.执行docker-compose up
效果
微信:17873041739