/bin/sh: 1: curl: not found with exit code: 127 means the program
your RUN step calls is not installed in the image you build from. Exit code 127
is the shell's own "command not found"; the command itself never started.
Install the tool in an earlier step of the same stage, or use a base image that already has
it. On Ubuntu based images, including the default aspnet:10.0 tag
(Ubuntu 24.04), that is
apt-get update && apt-get install -y curl.
The error
#5 [2/2] RUN curl -fsS http://example.com/ -o /dev/null
#5 0.194 /bin/sh: 1: curl: not found
#5 ERROR: process "/bin/sh -c curl -fsS http://example.com/ -o /dev/null" did not complete successfully: exit code: 127
The base image was mcr.microsoft.com/dotnet/aspnet:10.0. The step failed
within 0.2 seconds: the shell looked for curl, did not find it, and stopped
before any network request.
Why it happens
Docker runs every shell-form RUN line as /bin/sh -c "...". The
shell looks the first word up on PATH, finds nothing and exits with 127 before
any of your arguments matter. The 1: is the line number inside that one-line
script, not a line of your Dockerfile.
Runtime images are deliberately small. The ASP.NET Core and .NET runtime images contain the
runtime and the libraries it needs, not developer tools, so a Dockerfile copied from a
tutorial that used a full Ubuntu or SDK image breaks when its FROM line is
switched to a slimmer image. Multi-stage builds hit it too: a tool installed in the build
stage does not exist in the final stage.
The fix
FROM mcr.microsoft.com/dotnet/aspnet:10.0
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
RUN curl -fsS http://example.com/ -o /dev/null && echo curl-ok
With the install line added, the build installed curl (8.5.0-2ubuntu10.16) and
the next step printed curl-ok. If you only need curl for a health check, think
about whether it belongs in the final image at all: every tool you add there is something to
patch. On an Alpine base the package manager is apk instead of apt.
How it was reproduced
A folder with the two-line Dockerfile (the FROM line and the bare
curl step), built with
docker build --no-cache --progress=plain -t fix8-bld-p2 fix8-bld-p2 on Docker
Desktop engine 29.9.2; the aspnet:10.0 image carries .NET 10.0.13 on Ubuntu
24.04 packages. The fixed Dockerfile above was built the same way. The folder and tag names
are this test's own.
Frequently asked
- What does exit code 127 mean in a Docker build?
- It is the shell's code for command not found. The program named in the RUN step is not on the PATH of the image at that stage, so it never ran.
- Does the dotnet aspnet image include curl?
- No. The aspnet:10.0 runtime image ships without curl. Install it with apt-get update and apt-get install -y curl in a RUN step, or avoid needing it in the final image.
- Why is a tool missing in the final stage of a multi-stage build?
- Each FROM starts a new image. Tools installed in the build stage stay there; only files you COPY --from that stage reach the final one.
More decoded errors in the Fixes category. If the install step itself fails with "Unable to locate package", see the apt-get update fix.