【发布时间】:2025-12-04 15:20:06
【问题描述】:
我有一个使用 Angular 模板创建的 dotnet 核心应用程序,它与 postgresql 数据库通信。
在我的本地机器上,我在终端上运行以下命令来运行数据库容器:
docker run -p 5432:5432 --name accman-postgresql -e POSTGRES_PASSWORD=mypass -d -v 'accman-postgresql-volume:/var/lib/postgresql/data' postgres:10.4
然后在 VsCode 中按 F5,我发现我的应用程序运行良好。
为了 dockerise 我的应用程序,我将此文件添加到我的应用程序的根目录中。
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
# install nodejs for angular, webpack middleware
RUN apt-get update
RUN apt-get -f install
RUN apt-get install -y wget
RUN wget -qO- https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y build-essential nodejs
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Web.dll"]
现在我想我必须创建一个 docker-compose 文件。你能帮我创建我的 docker-compose.yml 文件吗?
谢谢,
【问题讨论】:
标签: postgresql docker .net-core docker-compose