Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - Ubuntu - bash: ping: command not found

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.

like image 254
Snowcrash Avatar asked Oct 06 '16 16:10

Snowcrash


People also ask

How do I install ping on Ubuntu?

To install ping command on your system, first of all, update system repositories using this command “$ sudo apt update && sudo apt upgrade”, then install the “iputils-ping” package that comprises the ping command with the “$ sudo apt install iputils-ping” command.

What is Dockerd command?

Docker creates a new container, as though you had run a docker container create command manually. Docker allocates a read-write filesystem to the container, as its final layer. This allows a running container to create or modify files and directories in its local filesystem.


1 Answers

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.

like image 151
Farhad Farahi Avatar answered Sep 20 '22 11:09

Farhad Farahi