我想创建一个aspnet.core容器和一个mysql容器,而aspnet.core容器应在启动时“等待” mysql容器。
现在我有一个aspnet.core容器,如此处所述:https://hub.docker.com/r/microsoft/aspnetcore-build/,并将其与mysql服务器的可能性结合在一起:https://docs.docker.com/compose/aspnet-mssql-compose/
那是我的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 ["/bin/bash", "./app/entrypoint.sh"]
CMD ["dotnet", "Test.dll"]
这是我的入口点。
#!/bin/bash
set -e
echo -e "\nWaiting for the Database-Service..."
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:
version: '3.1'
services:
ttestserver:
build: ./Test/
container_name: Test
ports:
- "5005:80"
depends_on:
- "database"
database:
build: ./database/docker
container_name: database
volumes:
- ./database/mysql:/mysql
- ./database/init-db:/docker-entrypoint-initdb.d
- dashboard-database-data:/var/lib/mysql/data
ports:
- "3306:3306"
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes
volumes:
dashboard-database-data:
driver: local
但是如果我通过docker-compose启动两个容器,则会收到以下错误消息:
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
Test | http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
Test | SQL Server is starting up
那就是一个循环。是否有机会让这些容器与该entrypoint.sh一起运行?使用php和mysql容器,使用php容器等待mysql容器相对容易