ping is missing inside a Docker container
bash: ping: command not foundShort answer
Base images such as ubuntu are minimal, so ping is simply not installed. Install the iputils-ping package with apt-get, and put that line in your Dockerfile so the container has it every time. If apt says it cannot find the package, run apt-get update first.
Fix it fast
1Find out which cause you have
Check that the image really lacks the binary, and which distribution you are in.
docker run --rm ubuntu:24.04 sh -c 'command -v ping || echo missing' cat /etc/os-release2Match what you see, then jump to its fix
What does the error look like?
bash: ping: command not foundsh: 1: ping: not foundE: Unable to locate package iputils-ping
Cause 1 of 2
The image does not ship ping
1Check
The ubuntu image is a minimal install; ping comes from the iputils-ping package in Debian-based systems.
dpkg -s iputils-ping2Fix
Install it inside a running container to try it, then move the same line to the Dockerfile.
apt-get update && apt-get install -y iputils-ping3Verify
ping can send a packet.
ping -c 2 127.0.0.1Confirmed by packages.debian.org
Cause 2 of 2
The package list is empty, so apt cannot find the package
1Check
Official images ship without package lists, so apt-get install fails until apt-get update has run in the same session.
ls /var/lib/apt/lists | head2Fix
Run update and install in one RUN line in the Dockerfile, so a cached update layer is never reused with an install.
RUN apt-get update && apt-get install -y --no-install-recommends \
iputils-ping \
&& rm -rf /var/lib/apt/lists/*3Verify
Rebuild the image and run ping in a new container.
docker build -t pingtest .
docker run --rm pingtest ping -c 2 127.0.0.1Confirmed by docs.docker.com
How do I stop it coming back?
- Install debug tools only in a separate debug image or stage, not in your production image.
- Always combine apt-get update with apt-get install in one RUN line.
- Use a connection test from your app side (a TCP check) instead of relying on ICMP, which many networks block.
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
Running ps inside a container says command not found
bash: ps: command not found
Slim Debian and Ubuntu images do not ship the procps package, and ps comes from procps.
2 causes, each with a fixServers
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
apt-get does not exist on this EC2 instance
sudo: apt-get: command not found
apt-get belongs to Debian and Ubuntu.
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
bash warns that it cannot change the locale after you log in to a server
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
The shell was told to use a locale that is not built on the server.
3 causes, each with a fixServers
Syntax error: redirection unexpected when a Bash script runs under sh
script.sh: 12: Syntax error: redirection unexpected
The operators <<< (here-string) and &> are Bash features.
3 causes, each with a fix