Search code examples
.netdockerkubernetesdockerfileworkdir

Why am I getting absolute path WORKDIR dockerfile vulnerability warning from Gitlab?


I have the following dockerfile for a project that is hosted with Kubernetes and Openshift and am getting a vulnerability warning from Gitlab that line 10 should use an absolute path instead of relative path for the sake of clarity and reliability. Is there something about a string path that dockerfile or Gitlab doesn't like? I am not getting the warnings for lines 3, 6, or 17. NOTE: I've replaced the docker image and project names below with placeholders surrounded by brackets.

1   FROM {docker-image1}
2   HEALTHCHECK CMD curl --fail -s http://localhost:8080/liveliness || exit 1
3   WORKDIR /app
4
5   FROM {docker-image2} AS build
6   WORKDIR /app/src
7   COPY ["{proj-path-string1}", "{proj-path-string2}"]
8   RUN dotnet restore --runtime linux-x64 "{proj-path-string1}"
9   COPY . .
10  WORKDIR "/app/src/{directory-name}"
11  RUN dotnet build --runtime linux-x64 "{project-name}" -c Release -o /app/build
12
13  FROM build AS publish
14  RUN dotnet publish --runtime linux-x64 "{project-name}" -c Release -o /app/publish
15
16  FROM base AS final
17  WORKDIR /app
18  COPY --from=publish /app/publish .
19
20  ENTRYPOINT ["dotnet", "{project-name}.dll"]```

Solution

  • Delete the quotes from that line, changing:

    WORKDIR "/app/src/{directory-name}"
    

    To:

    WORKDIR /app/src/{directory-name}