3

I pulled the Apache httpd image and ran a container. However, once, I'm inside a container, ping doesn't work and I see an error: "bash: ping: command not found". Can't even ping 127.0.0.1. Ping is working outside of a container.

cat /etc/resolv.conf shows the same nameserver, inside and outside of the container. I restarted the Docker service, but, it doesn't solve the problem either.

docker pull httpd
docker run -d --name testweb httpd
docker exec -it testweb /bin/bash
ping google.com

root@fb1ce4bccc11:/usr/local/apache2# ping google.com

bash: ping: command not found

I tried to install Ping, but the package manager can't find it:

root@fb1ce4bccc11:/usr/local/apache2# yum -y install iputils-20160308-10.el7.x86_64
bash: yum: command not found
halfer
  • 19,824
  • 17
  • 99
  • 186
FM2012
  • 61
  • 1
  • 1
  • 8
  • It depends what package manager the upstream image has installed. If it is not `yum`, then it might be `apt` or `apk` or something else. Would you point to the image you are using on Docker Hub? – halfer May 19 '19 at 19:18
  • I don't know how can I point to the image, that I'm using on Docker Hub. However, I do know the ID of the image, by running docker images, command. b7cc370ac278 – FM2012 May 19 '19 at 19:24
  • OK, what was the name of the image? `docker pull `. You should be able to get the name from the `docker images` command too. – halfer May 19 '19 at 19:25
  • docker pull httpd – FM2012 May 19 '19 at 19:26
  • OK, see the link I added to your post - that is where you are pulling it from. [The Dockerfile](https://github.com/docker-library/httpd/blob/75e85910d1d9954ea0709960c61517376fc9b254/2.4/Dockerfile) shows it is based on Ubuntu, so try `apt install -y iputils-ping` instead. – halfer May 19 '19 at 19:28
  • Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package iputils-ping – FM2012 May 19 '19 at 19:30
  • Heh, nearly there. Try `apt-get update -y && apt-get upgrade -y && apt-get install -y iputils-ping`. Bonus points for you if you can tell me what this does `:-)` – halfer May 19 '19 at 19:31
  • wow. It worked. Thank you very much for your time and help @halfer By the way, how did you figure out, the image is based on Ubuntu. – FM2012 May 19 '19 at 19:33
  • You are welcome. From your image name, I followed the `Dockerfile` link, and found the `FROM` line at the top. I made a mistake, it is Debian, not Ubuntu, but they are pretty much the same thing. The parent image is `debian:stretch-slim`. They both use the Apt dependency manager. – halfer May 19 '19 at 19:34
  • So, for your learning, what do those commands do? It's OK if you don't know, but it is good to learn (and it is necessary to learn if you are going to be using Docker). – halfer May 19 '19 at 19:35
  • *FROM* tells the source of the image, so, in our, case, it is debian:stretch-slim. *ENV* represents environment variable. That's all I know when it comes to knowing Dockerfile. I very new to Docker. – FM2012 May 19 '19 at 19:42
  • I meant the `apt-get` commands, but yes, the Docker directives are worth studying too. Try building and running your own image when you can. – halfer May 19 '19 at 19:50
  • Possible duplicate of [Docker - Ubuntu - bash: ping: command not found](https://stackoverflow.com/questions/39901311/docker-ubuntu-bash-ping-command-not-found) (thanks to Manfreds3 for finding it). – halfer May 19 '19 at 19:50
  • To my understanding, apt-get is similar to yum install. apt-get is used on Ubuntu based systems. – FM2012 May 19 '19 at 19:57
  • `apt-get update` refreshes the local software catalogue of what software is available in the remote OS mirror; `apt-get upgrade` installs the latest version of things that are installed but not at their latest version, and `apt-get install` installs things (generally at the latest available version) for things that are not installed at all. The install originally failed because you didn't have a local software catalogue until the `update` is run. – halfer May 19 '19 at 21:13

1 Answers1

23

I found a similar post: Docker - Ubuntu - bash: ping: command not found

My first choice would be running:

apt-get update
apt-get install iputils-ping
halfer
  • 19,824
  • 17
  • 99
  • 186
Manfreds3
  • 670
  • 1
  • 6
  • 7
  • *Note*: to work correctly, the second command requires a `-y`. This parameter is necessary to confirm the installation automatically. – Sarcares Jul 27 '22 at 16:32