docker asp.net核心容器在mysql容器之后启动 [英] docker asp.net core container starting after a mysql container

查看:91
本文介绍了docker asp.net核心容器在mysql容器之后启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有asp.net核心的docker容器和一个带有mysql的容器。现在我需要等待asp.net核心容器,以便mysql容器启动并准备就绪(两个容器都通过docker-compose.yml启动)。

i have a docker container with asp.net core and a container with mysql. Now i need to wait with asp.net core container for the mysql container is up and ready (both container are starting through docker-compose.yml).

类似于< a href = https://github.com/jwilder/dockerize rel = nofollow noreferrer> https://github.com/jwilder/dockerize ,wait-for-it.sh或wait-for似乎不适用于asp.net核心容器。

Something like https://github.com/jwilder/dockerize , wait-for-it.sh or wait-for seems not to work for asp.net core container.

有人知道如何解决该问题吗?

Have someone a clue how to solve the problem?

UPDATE

UPDATE

这是我的dockerfile:

this is my 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:

and this is my entrypoint.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启动容器,我得到了错误消息:

if i start the container with docker-compose i get the error msg:

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来等待数据库容器。有没有解决方案可以同时运行?

How can i combine the ENTRYPOINT and the CMD /bin/bash ./app/entrypoint.sh command in one file. I think i need the ENTRYPOINT for the dotnet applicatioin to run and the cmd for the entrypoint.sh to wait for the database container. Is there a solution get both to run?

推荐答案

https://docs.docker.com/compose/aspnet-mssql-compose/

docker文档列出了如何获取一个ASP.net容器通过让entrypoint.sh轮询数据库连接来等待它的数据库。

The docker docs list how to get an ASP.net container to wait for it's databases by having the entrypoint.sh poll for DB connectivity.

#!/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 asp.net核心容器在mysql容器之后启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆