Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

ping is missing inside a Docker container

Errorbash: ping: command not found

Short 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.

  • Applies to Docker Engine 28, ubuntu 24.04 image
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-release
  2. 2Match what you see, then jump to its fix

    1. 1bash: ping: command not foundThe image does not ship pingFix
    2. 2E: Unable to locate package iputils-pingThe package list is empty, so apt cannot find the packageFix

What does the error look like?

  • bash: ping: command not found
  • sh: 1: ping: not found
  • E: 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-ping

2Fix

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-ping

3Verify

ping can send a packet.

ping -c 2 127.0.0.1

Confirmed by packages.debian.org

Did this fix it?

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 | head

2Fix

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.1

Confirmed by docs.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.