4

I tried to run a dotnet command located in a shell file which will be called by dockerfile during the docker build process.

Here is the dockerfile snippet:

FROM ubuntu:16.04
FROM microsoft/dotnet:2.2-sdk as build-env

# .net core 
RUN apt-get update -y && apt-get install -y wget apt-transport-https
RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && dpkg -i packages-microsoft-prod.deb
RUN apt-get update -y && apt-get install -y aspnetcore-runtime-2.2=2.2.1-1

# dotnet tool command
RUN apt-get update -y && apt-get install dotnet-sdk-2.2 -y
# for dot net tool #https://stackoverflow.com/questions/51977474/install-dotnet-core-tool-dockerfile
ENV PATH="${PATH}:/root/.dotnet/tools"

# Supervisor
RUN apt-get update -y && apt-get install -y supervisor && mkdir -p /etc/supervisor

# main script as defacult command when docker container runs
# Run the main sh script to run script in each xxx/*/db-migrate.sh. 
CMD ["/xxx/main-migrate.sh"]

# Microservice files
ADD xxx /xxx

# install the xxx deploy tool
WORKDIR /xxx
RUN for d in /xxx/*/ ; do cd "$d"; if [ -f "./install.sh" ]; then sh ./install.sh; fi; done

In the install.sh, here is the code:

dotnet tool install -g xxx.DEPLOY --version [$(cat version)] --add-source /xxx/

When I run docker build -t xxx:v0 ., I get an error message saying:

./install.sh: 1: ./install.sh: dotnet: not found

I have added FROM microsoft/dotnet:2.2-sdk as build-env & RUN apt-get update -y && apt-get install dotnet-sdk-2.2 -y, but why Docker could not find the dotnet command during build?

How do I call the dotnet command located in the shell script file during the docker build process?

Thank you

user2150279
  • 445
  • 2
  • 8
  • 17

1 Answers1

2
FROM ubuntu:16.04
FROM microsoft/dotnet:2.2-sdk as build-env

In the above lines FROM ubuntu:16.04 will be totally ignored as there should be only one base image, so the last FROM will be considered as a base image which is FROM microsoft/dotnet:2.2-sdk not the ubuntu.

So if your base image is FROM microsoft/dotnet:2.2-sdk as build-env then why to bother to run these complex script to install dotnet?

You are good to go to check version of dotnet.

FROM microsoft/dotnet:2.2-sdk as build-env
RUN dotnet --version

output

Step 1/6 : FROM microsoft/dotnet:2.2-sdk as build-env
 ---> f13ac9d68148
Step 2/6 : RUN dotnet --version
 ---> Running in f1d34507c7f2

> 2.2.402

Removing intermediate container f1d34507c7f2
 ---> 7fde8596c331
Adiii
  • 54,482
  • 7
  • 145
  • 148
  • 1
    Your answer helped me to realize the reason why `dotnet` command could not be found. The wrong `FROM` part of my docker file caused it. Then I fixed it by changing it from `FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS build-env` to `FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env`. Thank you. – Tekin Feb 19 '23 at 18:55