admin管理员组

文章数量:1332377

I am getting an odd error when trying to build my dockerfile. It appears docker is not recognizing this as a valid command but I am not sure why.

Here is the start of my dockerfile where the error is occurring.

# Use the official .NET SDK image to build the app
FROM mcr.microsoft/dotnet/sdk:8.0 AS build
WORKDIR /src
ENV ASPNETCORE_ENVIRONMENT=Development
ENV CONNECTION_STRING=""
ENV JWT_KEY=""

# Copy the files
COPY . .

# Publish each project in the solution
RUN dotnet publish APIGateway -c Release -o /app/publish/APIGateway

# Use the official .NET runtime image to run the app
FROM mcr.microsoft/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

The 'RUN' command appears to be where the error is occurring. I have tried to rewrite the line thinking maybe some hidden invalid character got in there but that is not helping. 'dotnet' should be installed as I am starting from the dotnet sdk base image.

I am getting an odd error when trying to build my dockerfile. It appears docker is not recognizing this as a valid command but I am not sure why.

Here is the start of my dockerfile where the error is occurring.

# Use the official .NET SDK image to build the app
FROM mcr.microsoft/dotnet/sdk:8.0 AS build
WORKDIR /src
ENV ASPNETCORE_ENVIRONMENT=Development
ENV CONNECTION_STRING=""
ENV JWT_KEY=""

# Copy the files
COPY . .

# Publish each project in the solution
RUN dotnet publish APIGateway -c Release -o /app/publish/APIGateway

# Use the official .NET runtime image to run the app
FROM mcr.microsoft/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

The 'RUN' command appears to be where the error is occurring. I have tried to rewrite the line thinking maybe some hidden invalid character got in there but that is not helping. 'dotnet' should be installed as I am starting from the dotnet sdk base image.

Share Improve this question asked Nov 22, 2024 at 5:20 JAKDevJAKDev 132 bronze badges 2
  • Can you change your Dockerfile to FROM mcr.microsoft/dotnet/sdk:8.0 AS build (newline) RUN dotnet --version (newline) ENTRYPOINT ["dotnet", "--version"] and see if this works by itself. This works fine by itself for me: i.sstatic/pBusSDsf.png - dotnet works both as a step in the build via RUN and as the entrypoint for the image. – ProgrammingLlama Commented Nov 22, 2024 at 5:28
  • Have you checked whether you have any non printable characterters in your file? The error says the error is on line 13, but in your snippet line 13 is the empty line after the RUN – Flurin Commented Nov 22, 2024 at 6:36
Add a comment  | 

1 Answer 1

Reset to default 0

I found my issue. I had multiple docker files but each for a different application. I was missing the 'RUN' command from that line on just that file. It was so obvious I missed it. Thank you all for your suggestions!

本文标签: cfailed to solve dockerfile parse error on line 13 unknown instruction dotnetStack Overflow