无法安装在容器dotnet SDK 6.0和JDK 8中
我需要安装在同一容器dotnet SDK 6.0和JDK 8中,我已实现以下dockerfile,但会创建容器,并且在审查Java时,该容器未安装
## dockerfile,
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM ubuntu:20.04 AS build-jdk
RUN apt-get update && \
apt-get install -y openjdk-8-jre && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY --from=build-jdk ./* ./
COPY . .
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /app/usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
WORKDIR /src
COPY ["DigitalSignature.csproj", "./"]
RUN dotnet restore "DigitalSignature.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "DigitalSignature.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "DigitalSignature.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DigitalSignature.dll"]
但在检查Java是否已安装时,它是否已安装,它是否已安装,不会出现
命令
java -version
Java -version
printenv | env
I need to install in the same container dotnet sdk 6.0 and jdk 8, I am implemented the following dockerfile but creates the container and when reviewing java this does not appear installed
##Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM ubuntu:20.04 AS build-jdk
RUN apt-get update && \
apt-get install -y openjdk-8-jre && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY --from=build-jdk ./* ./
COPY . .
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /app/usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
WORKDIR /src
COPY ["DigitalSignature.csproj", "./"]
RUN dotnet restore "DigitalSignature.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "DigitalSignature.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "DigitalSignature.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DigitalSignature.dll"]
The container is created but when checking if java is installed, it does not appear
commands
java -version
Java -version
printenv | env
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在
build
dockerfile的阶段(from mcr.microsoft.com/dotnet/sdk:6.0 as Build
)中复制和配置Java(构建您的.NET项目。该阶段在文件图像中不使用。因此,从该阶段没有明确复制到最后阶段的任何东西都会被抛弃。
我建议将安装/配置Java的命令移至Dockerfile的初始阶段,一个标记为
base
。最终
阶段基于base
,因此图像中的任何内容都将可用。在
base
阶段中,将其放置在Visual Studio中的“快速调试”容器功能时,可以使用它。You're copying and configuring Java in the
build
stage of the Dockerfile (FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
) but that stage is only used to build your .NET project. That stage is not used in the file image. So anything that's not explicitly copied from that stage into the final stage essentially gets thrown out.I would suggest moving your commands that install/configure Java up to the initial stage of the Dockerfile, the one labeled
base
. Thefinal
stage is based onbase
so anything included in their will be available in your image.Having it in the
base
stage will allow it to be available when using the "fast debug" container feature in Visual Studio too.我能够解决下一个Dockerfile的问题
I was able to solve the problem with the next Dockerfile