Docker - Ubuntu - bash: ping: command not found

UbuntuDockerPing

Ubuntu Problem Overview


I've got a Docker container running Ubuntu which I did as follows:

docker run -it ubuntu /bin/bash

however it doesn't seem to have ping. E.g.

bash: ping: command not found

Do I need to install that?

Seems a pretty basic command to be missing. I tried whereis ping which doesn't report anything.

Ubuntu Solutions


Solution 1 - Ubuntu

Docker images are pretty minimal, but you can install ping in your official ubuntu docker image via:

apt-get update
apt-get install iputils-ping

Chances are you don't need ping on your image, and just want to use it for testing purposes. Above example will help you out.

But if you need ping to exist on your image, you can create a Dockerfile or commit the container you ran the above commands into a new image.

Commit:

docker commit -m "Installed iputils-ping" --author "Your Name <[email protected]>" ContainerNameOrId yourrepository/imagename:tag

Dockerfile:

FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash

Please note there are best practices on creating docker images, like clearing apt cache files afterwards and etc.

Solution 2 - Ubuntu

This is the Docker Hub page for Ubuntu and this is how it is created. It only has (somewhat) bare minimum packages installed, thus if you need anything extra you need to install it yourself.

apt-get update && apt-get install -y iputils-ping

However usually you'd create a "Dockerfile" and build it:

mkdir ubuntu_with_ping
cat >ubuntu_with_ping/Dockerfile <<'EOF'
FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash
EOF
docker build -t ubuntu_with_ping ubuntu_with_ping
docker run -it ubuntu_with_ping

Please use Google to find tutorials and browse existing Dockerfiles to see how they usually do things :) For example image size should be minimized by running apt-get clean && rm -rf /var/lib/apt/lists/* after apt-get install commands.

Solution 3 - Ubuntu

Alternatively you can use a Docker image which already has ping installed, e.g. busybox:

docker run --rm busybox ping SERVER_NAME -c 2

Solution 4 - Ubuntu

Generally people pull the official image of Ubuntu/CentOS but they don't realize that these images are minimal and doesn't have any thing on the top of that.

For Ubuntu, this image is built from official rootfs tarballs provided by Canonical. Given that it is a minimal install of Ubuntu, this image only includes the C, C.UTF-8, and POSIX locales by default.

One can install net-tools (includes ifconfig, netstat), ip-utils(includes ping) andy other likes curl etc on container and can create image from container or can write Dockerfile that will install these tool while creating image.

Below is Dockerfile example, while creating image from this it will include these tools:

FROM vkitpro/ubuntu16.04
RUN     apt-get  update -y \
&& apt-get upgrade -y \
&& apt-get install iputils-ping -y \
&& apt-get install net-tools -y \
CMD bash

or launch container from base image and install these utilities on container and then commit to image. docker commit -m "any descriptive message" container_id image_name:lattest

That image will have all thing installed.

Solution 5 - Ubuntu

Sometimes, the minimal installation of Linux in Docker doesn't define the path and therefore it is necessary to call ping using ....

cd /usr/sbin
ping <ip>

Solution 6 - Ubuntu

I have used the statement below on debian 10

apt-get install iputils-ping

Solution 7 - Ubuntu

Every time you get this kind of error

bash: <command>: command not found
  • On a host with that command already working with this solution:

      dpkg -S $(which <command>)
    
  • Don't have a host with that package installed? Try this:

      apt-file search /bin/<command>
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSnowcrashView Question on Stackoverflow
Solution 1 - UbuntuFarhad FarahiView Answer on Stackoverflow
Solution 2 - UbuntuNikoNyrhView Answer on Stackoverflow
Solution 3 - UbuntuIvanView Answer on Stackoverflow
Solution 4 - UbuntuVaseem007View Answer on Stackoverflow
Solution 5 - UbuntuAlex JavarottiView Answer on Stackoverflow
Solution 6 - UbuntuAnthony WambuiView Answer on Stackoverflow
Solution 7 - UbuntuPablo BianchiView Answer on Stackoverflow