无法安装在容器dotnet SDK 6.0和JDK 8中

发布于 2025-01-31 18:25:07 字数 1407 浏览 4 评论 0原文

我需要安装在同一容器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

检查Java和环境变量

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

checking java and environment variables

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴梦长久 2025-02-07 18:25:07

您正在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. The final stage is based on base 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.

愿与i 2025-02-07 18:25:07

我能够解决下一个Dockerfile的问题

FROM ubuntu:18.04 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
    software-properties-common

## Install Oracle's JDK
# add oracle jdk repository
RUN add-apt-repository ppa:ts.sch.gr/ppa && \
# accept oracle license
    echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set- 
selections && \
    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set- 
selections && \
    apt-get update && \
# install oracle jdk 8 and make it default


apt-get -y install oracle-java8-installer && \
  apt-get -y install oracle-java8-set-default && \
# clean up
  apt-get clean all && \
  rm -rf /var/lib/apt/lists/*   

 Run wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
     dpkg -i packages-microsoft-prod.deb && \
     rm packages-microsoft-prod.deb

 Run apt-get update; \
     apt-get install -y apt-transport-https && \
     apt-get update && \
     apt-get install -y dotnet-sdk-6.0

Run apt-get update; \
    apt-get install -y apt-transport-https && \
    apt-get update && \
    apt-get install -y aspnetcore-runtime-6.0


FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
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 .
ENV ASPNETCORE_URLS=http://+:80
ENTRYPOINT ["dotnet", "DigitalSignature.dll"]

I was able to solve the problem with the next Dockerfile

FROM ubuntu:18.04 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
    software-properties-common

## Install Oracle's JDK
# add oracle jdk repository
RUN add-apt-repository ppa:ts.sch.gr/ppa && \
# accept oracle license
    echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set- 
selections && \
    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set- 
selections && \
    apt-get update && \
# install oracle jdk 8 and make it default


apt-get -y install oracle-java8-installer && \
  apt-get -y install oracle-java8-set-default && \
# clean up
  apt-get clean all && \
  rm -rf /var/lib/apt/lists/*   

 Run wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
     dpkg -i packages-microsoft-prod.deb && \
     rm packages-microsoft-prod.deb

 Run apt-get update; \
     apt-get install -y apt-transport-https && \
     apt-get update && \
     apt-get install -y dotnet-sdk-6.0

Run apt-get update; \
    apt-get install -y apt-transport-https && \
    apt-get update && \
    apt-get install -y aspnetcore-runtime-6.0


FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
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 .
ENV ASPNETCORE_URLS=http://+:80
ENTRYPOINT ["dotnet", "DigitalSignature.dll"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文