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
pingwhen 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!
We earn commissions when you shop through the links below.
DigitalOcean
Cloud infrastructure for developers
Simple, reliable cloud computing designed for developers
DevDojo
Developer community & tools
Join a community of developers sharing knowledge and tools
Acronis
The most secure backup
Acronis: the most secure backup solution for your data
Want to support DevOps Daily and reach thousands of developers?
Become a SponsorFound an issue?