我对这一切的工作方式有些困惑,因为这是我第一次玩Docker。
我已经下载了以下Microsoft SQL Server Express的docker镜像(https://hub.docker.com/r/microsoft/mssql-server-windows-express/)。
我正在尝试将一些现有容器进行docker组合,每次运行docker-compose up
时,我想发生的事情是创建一个新数据库并运行一个目标容器。
这是我要执行的容器的现有Dockerfile。 “执行此”是我要运行dotnet run
的容器,任何“ HelperService”是在运行目标容器之前应启动的服务:
FROM microsoft/dotnet:2.0-runtime-nanoserver-1709 AS base
WORKDIR /app
FROM microsoft/dotnet:2.0-sdk-nanoserver-1709 AS build
WORKDIR /src
COPY ExecuteThis/ExecuteThis.csproj ExecuteThis/
COPY ../HelperService/HelperService.csproj ../HelperService/
COPY ../HelperService2/HelperService2.csproj ../HelperService2/
COPY ../HelperService3/HelperService3.csproj ../HelperService3/
COPY ../HelperService4/HelperService4.csproj ../HelperService4/
COPY ../HelperService5/HelperService5.csproj ../HelperService5/
COPY ../HelperService6/HelperService6.csproj ../HelperService6/
RUN dotnet restore ExecuteThis/ExecuteThis.csproj
COPY . .
WORKDIR /src/ExecuteThis
RUN dotnet build ExecuteThis.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish ExecutThis.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ExecuteThis.dll"]
这是一个docker-compose.yml
文件:
version: '3.4'
services:
sqlserver:
image: microsoft/mssql-server-windows-express
helperservice:
image: helperservice
helperservice2:
image: helperservice2
helperservice3:
image: helperservice3
helperservice4:
image: helperservice4
helperservice5:
image: helperservice5
helperservice6:
image: helperservice6
executethis:
image: ${DOCKER_REGISTRY}executethis
depends_on:
- sqlserver
- helperservice
- helperservice2
- helperservice3
- helperservice4
- helperservice5
- helperservice6
build:
context: .
dockerfile: ExecuteThis\Dockerfile
我的问题是:如何生成数据库,这些指令应该写在哪里?如何dotnet run
我的“ ExecuteThis”容器?