简体   繁体   English

如何修改我的 DOCKERFILE 以将 wget 安装到 kubernetes pod 中?

[英]How do I modify my DOCKERFILE to install wget into kubernetes pod?

Right now my DOCKERFILE builds a dotnet image that is installed/updated and run inside its own pod in a Kubernetes cluster.现在,我的 DOCKERFILE 构建了一个 dotnet 映像,该映像已安装/更新并在 Kubernetes 集群中它自己的 pod 内运行。

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
ARG DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
ARG DOTNET_CLI_TELEMETRY_OPTOUT=1
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
ARG DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
ARG DOTNET_CLI_TELEMETRY_OPTOUT=1
ARG ArtifactPAT
WORKDIR /src

RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*

COPY /src .

RUN dotnet restore "./sourceCode.csproj" -s "https://api.nuget.org/v3/index.json"

RUN dotnet build "./sourceCode.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "./sourceCode.csproj" -c 
Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SourceCode.dll"]
EXPOSE 80

The cluster is very bare-bones and does not include either curl nor wget on it.该集群非常简单,不包括 curl 和 wget。 So, I need to get wget or curl installed in the pod/cluster to execute scripted commands that are set to run automatically after deployment and startup are completed.因此,我需要在 pod/cluster 中安装 wget 或 curl 以执行设置为在部署和启动完成后自动运行的脚本命令。 The command to do the install:执行安装的命令:

RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*

within the DOCKERFILE seems to do nothing to install in the Kubernetes cluster. DOCKERFILE 内的安装在 Kubernetes 集群中似乎没有任何作用。 As after the build run and deploys if I were to exec into the pod and try to run在构建运行和部署之后,如果我要执行到 pod 并尝试运行

wget --help 

I get wget doesn't exist.我得到 wget 不存在。 I do not have a lot of experience build DOCKERFILEs so I am truely getting stumped.我没有很多构建 DOCKERFILE 的经验,所以我真的被难住了。 And I want this automated in the DOCKERFILE as I will not be able to log into environments above our Test to perform the install manually.而且我希望在 DOCKERFILE 中自动执行此操作,因为我将无法登录到测试上方的环境以手动执行安装。

its not related to kubernetes nor pods.它与 kubernetes 或 pods 无关。 Actually you cant install anything to kubernetes pod.实际上你不能在 kubernetes pod 上安装任何东西。 you can install packages to containers which runs on pod.您可以将软件包安装到在 pod 上运行的容器中。

Your problem is that, you install wget to your build image.您的问题是,您将 wget 安装到您的构建映像中。 when you use this image below you lost all installed packages.当您使用下面的图片时,您丢失了所有已安装的软件包。 because those packages belong to build image.因为这些包属于构建映像。 build, base, final they are different images.you need to copy files explicitly like you did final image. build, base, final 它们是不同的图像。你需要像做最终图像一样明确地复制文件。 like this像这样

  COPY --from=publish /app .

so add command in the below to your final image and you can use wget without no problem.因此,将下面的命令添加到您的最终图像中,您就可以毫无问题地使用 wget。

RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*

see this link for more info && best practices.有关更多信息&&最佳实践,请参阅此链接。
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/ https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/

Everything between:之间的一切:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
ARG DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
ARG DOTNET_CLI_TELEMETRY_OPTOUT=1
WORKDIR /app

and:和:

FROM base AS final

is irrelevant.无关紧要。 With that line, you start constructing a new image from base which was defined in the first block.使用该行,您开始从第一个块中定义的base构建一个新图像。

(Incidentally, on the next line, you duplicate the WORKDIR statement needlessly. Also, final is the name you'll use to refer to base , it isn't a name for this finally defined image, so that doesn't really make sense - you don't want to do eg COPY --from=final .) (顺便说一句,在下一行,您不必要地重复了WORKDIR语句。此外, final是您将用来引用base的名称,它不是这个最终定义的图像的名称,因此这没有意义- 你不想做例如COPY --from=final 。)

You need to install wget in either the base image, or in the last defined image which you'll actually be running, at the end.最后,您需要在base映像或最后定义的实际运行的映像中安装wget

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 kubernetes 中运行时,我是否需要在 Dockerfile 中指定 UID - Do I need to specify an UID in my Dockerfile when running in kubernetes 如何使用我的 dockerfile 为我的 nodejs 应用程序安装 openjdk-16-jdk? - How do I install openjdk-16-jdk for my nodejs app using my dockerfile? 更新dockerfile后如何在kubernetes中重新部署所有内容? - How do I redeploy everything in kubernetes after updating a dockerfile? 如何设置我的 Dockerfile 以使用 cpanm 安装 Perl 模块的特定版本? - How do I set up my Dockerfile to use cpanm to install a specific version of a Perl module? 如何将我的 Kube.netes pod 连接到远程 Jaeger? - How can I connect my Kubernetes pod to a remote Jaeger? 如何在此Kubernetes示例中选择主Redis窗格? - How do I select the master Redis pod in this Kubernetes example? 如何将Kubernetes配置图复制到Pod的可写区域? - How do I copy a Kubernetes configmap to a write enabled area of a pod? 如何从 Kubernetes pod 中运行 curl 命令 - How do I run curl command from within a Kubernetes pod 如何在minikube节点上的kubernetes pod中设置sysctl密钥? - How do I set sysctl key in kubernetes pod on a minikube node? 安装后如何设置Dockerfile以运行babel? - How do I setup Dockerfile to run babel after install?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM