Docker - Ubuntu - bash: ping: command not found

I have a Docker container running Ubuntu, which I did as follows:

docker run -it ubuntu /bin/bash 

however, it does not seem to have ping . For example.

 bash: ping: command not found 

Does it need to be installed?

It seems that the main team is missing. I tried whereis ping , which doesn't say anything.

+159
docker ubuntu ping
Oct 06 '16 at 16:33
source share
5 answers

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

 apt-get update apt-get install iputils-ping 

Most likely, you do not need to ping your image and just want to use it for testing. The above example will help you.

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

Commit:

 docker commit -m "Installed iputils-ping" --author "Your Name <name@domain.com>" ContainerNameOrId yourrepository/imagename:tag 

Dockerfile:

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

Note that there are recommendations for creating docker images, for example, clearing apt cache files after, etc.

+334
Oct 06 '16 at 16:41
source share

This is the Docker Hub page for Ubuntu, and so it is created. Only (a few) minimum minimum packages are installed on it, so if you need something extra, you need to install it yourself.

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

However, usually you create a Dockerfile and create 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 view existing Docker files to see how they usually work :) For example, the image size should be minimized with the command apt-get clean && rm -rf/var/lib/apt/lists/* after apt-get install command.

+18
Oct 06 '16 at 16:41
source share

Alternatively, you can use a Docker image that already has ping installed, for example busybox :

 docker run --rm busybox ping SERVER_NAME -c 2 
+1
Sep 13 '18 at 11:18
source share

Usually people pull the official Ubuntu / CentOS image, but they don’t realize that these images are minimal and have nothing to do with it.

For Ubuntu, this image was created from official tarfs rootfs provided by Canonical. Given that this is a minimal Ubuntu installation, this default image includes only the C, C.UTF-8, and POSIX locales.

You can install net-tools (including ifconfig, netstat), ip-utils (including ping) and any other similar curl, etc. You can create an image from the container on the container or write a Dockerfile that will install this tool when creating the image.

Below is an example of a Dockerfile, when creating an image from it, the following tools will be used:

 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 run the container from the base image and install these utilities in the container, and then capture the image. docker commit -m "any descriptive message" container_id image_name: lattest

Everything will be installed in this image.

+1
Dec 21 '18 at 5:44
source share

Every time you get such an error

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

     dpkg -S $(which <command>) 
  • You do not have a host with the package installed? Try this :

     apt-file search /bin/<command> 
0
Jan 31 '19 at 3:01
source share



All Articles