如何为.Net Core2.2和Angular7应用创建一个docker镜像?

时间:2019-03-06 14:05:58

标签: angular docker asp.net-core

我有一个angular7应用程序,它位于.Net Core 2.2文件夹(如Controllers等)旁边的名为front的文件夹中。如何为.Net Core和Angular应用程序创建一个映像?可能吗? 这是我的dockerfile和我的docker-compose文件: Dockerfile:

# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

docker-compose.yml:

TIMESTAMP

1 个答案:

答案 0 :(得分:1)

如果我理解正确,那么您的问题。

您需要将Angular代码复制到容器中。

您的Dockerfile将是:

FROM microsoft/dotnet:sdk AS build-env
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

# ENV ASPNETCORE_ENVIRONMENT Development

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
#Copy static content
COPY front/ /app/front/
ENTRYPOINT ["dotnet", "test.dll"]  

现在,您需要将应用程序配置为从/ app / front目录获取前端。

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles(); // For the wwwroot folder

    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider("/app/front"),
        RequestPath = "/front"
    });
}

对不起,我的C#不好... Here the documentation