Skip to main content
6 min read

Docker - Ubuntu - bash: ping: command not found [closed]

Docker - Ubuntu - bash: ping: command not found [closed]

TLDR

If you see bash: ping: command not found in an Ubuntu-based Docker container, install the iputils-ping package using apt-get install.


The ping command is often used to test network connectivity, but it may not be available in minimal Ubuntu-based Docker images. This guide explains how to resolve the issue and why it happens.

Why Is ping Missing?

Minimal Docker images, like ubuntu:latest, exclude many utilities to keep the image size small. The ping command is part of the iputils-ping package, which is not installed by default.

Installing ping in a Docker Container

To install ping, you need to update the package list and install the iputils-ping package:

# Start a shell in the container
docker exec -it <container_name_or_id> bash

# Update package list
apt-get update

# Install iputils-ping
apt-get install -y iputils-ping

Now you can use the ping command inside the container.

Making the Change Persistent

If you frequently need ping in your containers, add it to your Dockerfile:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y iputils-ping

Build the image:

docker build -t ubuntu-with-ping .

This way, every time you run a container from this image, ping will be available. For example:

docker run --rm -it ubuntu-with-ping bash

You can now use ping without any issues.

Best Practices

  • Use minimal images for production to reduce attack surface.
  • Only install tools like ping when needed for debugging or testing.
  • Document any manual changes to containers.

By following these steps, you can quickly resolve the ping: command not found error and ensure your containers have the tools you need.

Good luck with your project!

Run the commands from this article in the browser. Nothing to install.

Published: 2024-09-10|Last updated: 2025-11-23T09:00:00Z

Found an issue?

Also worth your time on this topic