我是Docker的新手,我想把一个用Visual Studio中的ASP.NET Core with ReactJS
模板创建的项目dockerize。我的Docker文件看起来像这样,基于Quickstart: Use Docker with a React Single-page App in Visual Studio中的指南:
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get install -y nodejs
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get install -y nodejs
WORKDIR /src
COPY ["SampleWeb/SampleWeb.csproj", "SampleWeb/"]
RUN dotnet restore "SampleWeb/SampleWeb.csproj"
COPY . .
WORKDIR "/src/SampleWeb"
RUN dotnet build "SampleWeb.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SampleWeb.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SampleWeb.dll"]
然而,虽然可以使用Docker作为配置文件调试网页,但为了使其成功,我需要在SampleWeb/ClientApp
目录下运行命令提示符runnpm run start。当项目开始调试时,我是否可以在容器中运行此命令?有没有可以添加到Dockerfile中的命令,或者项目启动配置可以帮助我完成这一点?谢谢你。
1条答案
按热度按时间qv7cva1a1#
如果你想在容器启动时执行多个命令,你可以使用例如一个
start.sh
bash脚本,其中包含以下命令:然后,相应地更改您的Dockerfile: