Docker上的Asp.Net Core + SQL Server – 启动数据库的睡眠
我注意到,当我第一次尝试运行docker-compose up命令时出现错误:
Starting mssql ... Starting mssql ... done Recreating api ... Recreating api ... done Attaching to mssql, api api exited with code 1
因为api尝试从数据库获取数据,但MSSQL尚未启动。
所以,我的问题是有可能以某种方式等待数据库,然后运行API?
这是我的docker-compose和dockerfile
docker-compose:version:'3.3'
服务:
api: image: api container_name: api build: context: . dockerfile: Dockerfile ports: - "8000:80" depends_on: - db db: image: "microsoft/mssql-server-linux" container_name: mssql environment: SA_PASSWORD: "testtest3030!" ACCEPT_EULA: "Y" MSSQL_PID: "Express" ports: - "8001:1433"
dockerfile:
# Build Stage FROM microsoft/aspnetcore-build as build-env WORKDIR /source COPY . . RUN dotnet restore RUN dotnet publish -o /publish --configuration Release # Publish Stage FROM microsoft/aspnetcore WORKDIR /app COPY --from=build-env /publish . ENTRYPOINT ["dotnet", "Api.dll"]
我也注意到在日志中:
2017-11-17 22:12:42.67 Logon Error: 18456, Severity: 14, State: 38. 2017-11-17 22:12:42.67 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database 'MyDb'. [CLIENT: 172.26.0.3]
- 无法访问本地Docker容器上的Asp.Net Core
- 运行.net核心docker镜像,说应用程序启动了,但浏览时却给出了“This site can not be reached”的错误
- 如何使用Docker容器来设置ASP.NET Web应用程序
- Docker NPM安装不起作用
- 在Visual Studio代码中debuggingDocker上的ASP.NET Core
- 使用VSTS构build的.NET核心容器不能在Linux上运行
- Docker for Windows:ASP.NET站点无法读取在Dockerfile中定义的环境variables
- 如何在Docker群集模式负载平衡器中托pipeAsp.net应用程序
- ASP核心HttpClient.Get从容器到本地主机的网站是失败的