Docker Build step: Refresh user profile/session

Viewed 344

I have a docker file that install the .NET 5 SDK, and then tries to install a tool using dotnet tool install.

Upon doing so I get the warning:

Since you just installed the .NET SDK, you will need to logout or restart your session before running the tool you installed.

How do I logout or restart my session during a docker build?

I tried RUN echo "export PATH=/new/path:${PATH}" >> /root/.bashrc but that didn't seem to make any difference.


Paired down example:

FROM ubuntu as base-updates

RUN apt-get install -y wget
RUN wget https://packages.microsoft.com/config/ubuntu/20.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update; \
  apt-get install -y apt-transport-https && \
  apt-get update && \
  apt-get install -y dotnet-sdk-5.0

RUN dotnet tool install --global Amazon.Lambda.Tools

## executing the newly installed tool fails
RUN dotnet lambda --help
1 Answers

Work around from https://github.com/dotnet/dotnet-docker/issues/520 (big thanks @myeongkilkim!):

Explicitly updating the PATH did trick: ENV PATH="${PATH}:/root/.dotnet/tools"

FROM ubuntu as base-updates

RUN apt-get install -y wget
RUN wget https://packages.microsoft.com/config/ubuntu/20.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update; \
  apt-get install -y apt-transport-https && \
  apt-get update && \
  apt-get install -y dotnet-sdk-5.0

# FIX:
# manually add dotnet tools path to path variable
# https://github.com/dotnet/dotnet-docker/issues/520
ENV PATH="${PATH}:/root/.dotnet/tools"

RUN dotnet tool install --global Amazon.Lambda.Tools

## executing the newly installed tool now works :)
RUN dotnet lambda --help
Related