简体   繁体   中英

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.

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. 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. 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. As after the build run and deploys if I were to exec into the pod and try to run

wget --help 

I get wget doesn't exist. I do not have a lot of experience build DOCKERFILEs so I am truely getting stumped. 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.

its not related to kubernetes nor pods. Actually you cant install anything to kubernetes pod. you can install packages to containers which runs on pod.

Your problem is that, you install wget to your build image. 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. like this

  COPY --from=publish /app .

so add command in the below to your final image and you can use wget without no problem.

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/

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.

(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 .)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM