我有一个带有 asp.net core 的 docker 容器和一个带有 mysql 的容器。现在我需要等待 mysql 容器启动并准备好(两个容器都通过 docker-compose.yml 启动)。
就像是https://github.com/jwilder/dockerize https://github.com/jwilder/dockerize、wait-for-it.sh 或 wait-for 似乎不适用于 asp.net core 容器。
有人知道如何解决问题吗?
UPDATE
这是我的 dockerfile:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore test.csproj
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out test.csproj
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY ./entrypoint.sh ./app/
RUN chmod +x ./app/entrypoint.sh
CMD /bin/bash ./app/entrypoint.sh
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "test.dll"]
这是我的入口点.sh:
#!/bin/bash
set -e
run_cmd="dotnet run --server.urls http://*:80"
until dotnet ef database update; do
>&2 echo "SQL Server is starting up"
sleep 1
done
>&2 echo "SQL Server is up - executing command"
exec $run_cmd
如果我使用 docker-compose 启动容器,我会收到错误消息:
Unhandled Exception: System.FormatException: Value for switch '/app/entrypoint.sh' is missing.
test | at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()
test | at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
test | at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
test | at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
test | at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
test | at test.Program.Main(String[] args) in /app/Program.cs:line 19
如何将 ENTRYPOINT 和 CMD /bin/bash ./app/entrypoint.sh 命令合并到一个文件中。我想我需要 ENTRYPOINT 来运行 dotnet 应用程序,并需要 cmd 来为entrypoint.sh 等待数据库容器。有没有办法让两者都运行?
https://docs.docker.com/compose/aspnet-mssql-compose/ https://docs.docker.com/compose/aspnet-mssql-compose/
docker 文档列出了如何通过entrypoint.sh 轮询数据库连接来让 ASP.net 容器等待其数据库。
#!/bin/bash
set -e
run_cmd="dotnet run --server.urls http://*:80"
until dotnet ef database update; do
>&2 echo "SQL Server is starting up"
sleep 1
done
>&2 echo "SQL Server is up - executing command"
exec $run_cmd
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)