Problems installing ping in docker

67

5

I am trying to follow the docker tutorial but in a virtual machine. I've tried to install ping in ubuntu docker container with the command

sudo docker run ubuntu apt-get install ping

The problem is that docker doesn't install anything and gives the answer as follows

$ sudo docker run ubuntu apt-get install ping
Reading package lists...
Building dependency tree...
Package ping is a virtual package provided by:
  inetutils-ping 2:1.8-6
  iputils-ping 3:20101006-1ubuntu1

E: Package 'ping' has no installation candidate
$

The same problem appears when I'm trying to install anything.

These are my images:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              3a28cc5bcc53        19 minutes ago      247.6 MB
baselDaemon         latest              4e892058b0b2        4 days ago          204.4 MB
ubuntu              13.10               9f676bd305a4        2 weeks ago         178 MB
ubuntu              saucy               9f676bd305a4        2 weeks ago         178 MB
ubuntu              13.04               eb601b8965b8        2 weeks ago         166.5 MB
ubuntu              raring              eb601b8965b8        2 weeks ago         166.5 MB
ubuntu              12.10               5ac751e8d623        2 weeks ago         161 MB
ubuntu              quantal             5ac751e8d623        2 weeks ago         161 MB
ubuntu              10.04               9cc9ea5ea540        2 weeks ago         180.8 MB
ubuntu              lucid               9cc9ea5ea540        2 weeks ago         180.8 MB
ubuntu              12.04               9cd978db300e        2 weeks ago         204.4 MB
ubuntu              latest              9cd978db300e        2 weeks ago         204.4 MB
ubuntu              precise             9cd978db300e        2 weeks ago         204.4 MB
learn/tutorial      latest              8dbd9e392a96        10 months ago       128 MB

Also, when I run sudo docker run ubuntu apt-get install ping what is the 'ubuntu' used here?

Thank you in advance.

user3327759

Posted 2014-02-19T12:13:59.430

Reputation:

Visit : http://askubuntu.com/q/14685

– Pandya – 2014-09-09T09:23:29.043

If your installing ping, may be useful to also include nslookup; apt-get install dnsutils – PodTech.io – 2017-10-18T23:18:59.860

Answers

79

According to:

Package ping is a virtual package provided by:
  inetutils-ping 2:1.8-6
  iputils-ping 3:20101006-1ubuntu1

E: Package 'ping' has no installation candidate

Try with:

sudo docker run ubuntu apt-get install iputils-ping

You choose a 'ubuntu' with repository:tag in place of IMAGE in RUN command

sudo docker run ubuntu:lucid command

VTacius

Posted 2014-02-19T12:13:59.430

Reputation: 911

2Which command did you run to get this info "Package ping is a virtual package provided by: ..."? – Carl G – 2016-06-18T21:23:05.467

bash shows that message when you call a command that is not found. Not sure how though. – nicooga – 2017-04-18T20:28:36.237

20

run apt-get update once before the install:

sudo docker run ubuntu apt-get update

see What does sudo apt-get update do?

apt-get update downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies.

Michael_Scharf

Posted 2014-02-19T12:13:59.430

Reputation: 521

1This works prefectly.

docker run -it ubuntu bash, then: apt-get update; apt-get install iputils-ping – formica – 2016-07-17T19:18:40.280

8

Yeah ultimately you need to know about three different topics:

  1. Docker
  2. Ubuntu
  3. APT repositories

Here's how I like to get Ubuntu running in a Docker container:

docker run -i -t ubuntu:16.04 /bin/bash

Echoing what @Michael_Scharf recommends, here's how you update your APT repositories:

apt-get update

Then working back to @VTacius' solution, here's how to install the IP utilities responsible for the ping command:

apt-get install iputils-ping

Then to verify things are working as expected:

which ping
ping superuser.com

palmbardier

Posted 2014-02-19T12:13:59.430

Reputation: 93

Your answer is like the others – yass – 2017-04-21T16:19:36.670

Perhaps that's true. I just found that each answer in and of itself didn't resolve my problem. Each answer was specific to a different piece of the puzzle, and when applied in the correct order, the combination of these other answers did resolve my issue. – palmbardier – 2017-04-28T19:03:22.353

2

Faced the same issue when using ubuntu 16.04 image in docker.

The following steps helped me resolve this issue.

  1. Login to docker container as bash

    $ docker exec -it <conatiner id> bash
    
  2. inside the docker container, execute following commands. First update apt-get

    $ apt-get update
    
  3. Second install iputils-ping

    $ apt-get install iputils-ping
    

This should work.

Tapan Hegde

Posted 2014-02-19T12:13:59.430

Reputation: 21