apt-get is not found while building a Docker image
/bin/sh: apt-get: not foundShort answer
apt-get belongs to Debian and Ubuntu. If the build says it is not found, your base image is a different system, most often Alpine, whose package tool is apk. Check the image's operating system, then use the command that image has. A minimal image may have no package tool at all.
Fix it fast
1Find out which cause you have
Print the operating system of the base image in your FROM line. Its name decides which package command exists.
docker run --rm alpine:3.22 cat /etc/os-release2Match what you see, then jump to its fix
What does the error look like?
/bin/sh: apt-get: not found
Cause 1 of 2
The base image is Alpine, which uses apk
1Check
Alpine's package manager is apk. Check the FROM line of the Dockerfile.
grep -n "^FROM" Dockerfile2Fix
Replace the apt-get commands with apk. apk add downloads packages from the repositories listed in /etc/apk/repositories. Alpine package names can differ from Debian names, so search for each one.
RUN apk update && apk add bash curl3Verify
Rebuild the image without cache and watch the step finish.
docker build --no-cache -t my-app .Confirmed by docs.alpinelinux.org
Cause 2 of 2
The final image is a minimal one that holds only your program
1Check
The scratch base is used to create minimal images with only what an application needs, and the next Dockerfile command becomes its first filesystem layer. Nothing is there to install packages with.
grep -n "^FROM" Dockerfile2Fix
Do the installs in an earlier stage that uses a full base image, then copy the finished files into the minimal stage.
FROM debian:bookworm AS build
RUN apt-get update && apt-get install -y build-essential
COPY . /src
RUN make -C /src
FROM scratch
COPY --from=build /src/my-program /my-program3Verify
Rebuild; the install step runs in the full stage and the final image builds.
docker build -t my-app .Confirmed by docs.docker.com
How do I stop it coming back?
- Pin the base image tag in FROM and write install commands for that exact system.
- Keep installs in the stage that has a package manager, and copy only results forward.
- Search the package index of the distribution you use before copying a package name from a tutorial.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A dev container port does not open in the browser when Docker runs on a remote host
If your application only accepts calls from localhost, it will reject connections from published ports
Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.
3 causes, each with a fix