bash: ping: command not found in an Ubuntu container means the image does not contain the iputils-ping package. Run apt-get update, then apt-get install -y iputils-ping, and ping works.

Do the update first. In a fresh ubuntu:24.04 container the install alone failed with E: Unable to locate package iputils-ping, because the image comes with no package lists.

The error

docker exec fix10-lc-r1 bash -ic 'ping -c 2 127.0.0.1 2>&1'
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
bash: ping: command not found

The first two lines come from starting an interactive shell without a terminal; the third is the error. The same line appeared in a container made from mcr.microsoft.com/dotnet/aspnet:10.0.

Why it happens

The ubuntu:24.04 image does not include ping, and neither did the ASP.NET Core runtime image in the test. Bash searched the PATH for ping, found nothing and printed the message. Nothing is wrong with the container's network: once the package was installed, the same command reached the loopback address with no other change.

The second surprise is the install itself. The image ships without the lists that tell apt which packages exist, so on a fresh container apt cannot find the name:

docker exec fix10-lc-r2 bash -c 'apt-get install -y iputils-ping 2>&1; echo exit=$?'
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package iputils-ping
exit=100

The fix

docker exec fix10-lc-r1 bash -ic 'apt-get update > /dev/null; echo update-exit=$? 2>&1'
...
update-exit=0

docker exec fix10-lc-r1 bash -ic 'apt-get install -y iputils-ping > /dev/null; echo install-exit=$? 2>&1'
...
debconf: delaying package configuration, since apt-utils is not installed
install-exit=0

docker exec fix10-lc-r1 bash -ic 'ping -c 2 127.0.0.1 2>&1'
...
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.091 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.034 ms

--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1008ms
rtt min/avg/max/mdev = 0.034/0.062/0.091/0.028 ms

The debconf line is a notice, not an error; the install returned 0. A package installed with docker exec lives only in that container: after removing it, a new container from ubuntu:24.04 answered bash: line 1: ping: command not found again. For every container, put the update and install in the Dockerfile in one RUN line:

Get-Content l2\pingdf\Dockerfile
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y iputils-ping

docker build -q -t fix10-lc-ping l2\pingdf
...
docker run --rm fix10-lc-ping ping -c 1 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.106 ms
...
docker run --rm fix10-lc-ping dpkg -S /usr/bin/ping
iputils-ping: /usr/bin/ping

The last command confirms the file belongs to iputils-ping.

The exit code tells a script what went wrong. In the container without the package, the missing command returned 127, so a health script can test for that code to tell "ping is not installed" apart from a ping that ran:

docker exec fix10-lc-r2 bash -c 'ping -c 1 127.0.0.1 2>&1; echo exit=$?'
bash: line 1: ping: command not found
exit=127

How it was reproduced

The captures were made in containers created from ubuntu:24.04 (Ubuntu 24.04.5 LTS, bash 5.2.21, apt 2.8.3) and mcr.microsoft.com/dotnet/aspnet:10.0 with docker run -d --name ... sleep infinity on Docker Engine 29.9.3, and the commands were sent with docker exec. The installed package was iputils-ping 3:20240117-1ubuntu0.1. The fix10-lc- container names are the test's own. Every command was sent from Windows PowerShell 5.1 exactly as shown, with the -c text in single quotes so it reached the container unchanged; a single quote inside that text is written twice, as PowerShell requires.

Frequently asked

Which package provides ping on Ubuntu?
iputils-ping. In the test docker run --rm fix10-lc-ping dpkg -S /usr/bin/ping printed iputils-ping: /usr/bin/ping.
Why does apt-get install iputils-ping say Unable to locate package?
A fresh ubuntu:24.04 container has no package lists. Run apt-get update first; in the test the install then returned 0.
How do I install ping in a Docker container?
Run apt-get update and then apt-get install -y iputils-ping inside the container, or put both in one RUN line of your Dockerfile so every container has it.

More decoded errors in the Fixes category. For the missing ip command see bash: ip: command not found, and for E: Unable to locate package in a Dockerfile see this post.