Reputation: 5451
The following are some of the docker Images present in my system:
root@labadmin-VirtualBox:/home/labadmin# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 1e0c3dd64ccd 13 days ago 187.9 MB
ubuntu latest 45bc58500fa3 5 weeks ago 126.9 MB
I want to install "smartmontools" in the container. But it is throwing an error " Unable to locate package smartmontools" as below :
root@labadmin-VirtualBox:/home/labadmin# docker run -it 1e0c3dd64ccd
root@b4954826a227:/# apt-get install smartmontools
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package smartmontools
root@b4954826a227:/# exit
exit
But when I do the same in Ubuntu machine it is working.
root@labadmin-VirtualBox:/home/labadmin# apt-get install smartmontools
Reading package lists... Done
Building dependency tree
Reading state information... Done
***smartmontools is already the newest version.***
0 upgraded, 0 newly installed, 0 to remove and 542 not upgraded.
root@labadmin-VirtualBox:/home/labadmin#
What difference in Ubuntu Containers and Ubuntu systems ? What is blocking the package to get installed in the containers ?
My requirement is to create a containers with some utilities with Ubuntu OS as base image:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y smartmontools
Upvotes: 2
Views: 1471
Reputation: 5451
The following procedure has helped me to resolve the issue :
root@labadmin-VirtualBox:/home/labadmin# docker run busybox ping -c 2 192.203.230.10
PING 192.203.230.10 (192.203.230.10): 56 data bytes
64 bytes from 192.203.230.10: seq=0 ttl=56 time=66.724 ms
64 bytes from 192.203.230.10: seq=1 ttl=56 time=54.786 ms
--- 192.203.230.10 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 45.815/56.947/66.724 ms
When you try to ping to google.com using the container it fails to reach because of DNS issue.
root@labadmin-VirtualBox:/home/labadmin# docker run busybox nslookup google.com
Server: 8.8.8.8
Address 1: 8.8.8.8
nslookup: can't resolve 'google.com'
Find out the DNS server used in your machine :
root@labadmin-VirtualBox:/home/labadmin# nm-tool |grep DNS
DNS: 172.24.100.50
DNS: 10.1.100.50
Execute the same by adding DNS IP:
root@labadmin-VirtualBox:/home/labadmin# docker run --dns 172.24.100.50 busybox nslookup google.com
Server: 172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name: google.com
Address 1: 2607:f8b0:4009:80c::200e ord36s01-in-x0e.1e100.net
Address 2: 172.217.4.110 ord36s04-in-f14.1e100.net
To resolve it permanently add the following content to a new file:
root@labadmin-VirtualBox:/home/labadmin# cat /etc/docker/daemon.json
{
"dns" : ["172.24.100.50", "8.8.8.8"]
}
More info on Docker DNS configuration : https://docs.docker.com/engine/userguide/networking/configure-dns/
Restart the docker service :
root@labadmin-VirtualBox:/home/labadmin# sudo service docker restart
docker stop/waiting
docker start/running, process 22291
root@labadmin-VirtualBox:/home/labadmin# docker run busybox nslookup google.com
Server: 172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name: google.com
Address 1: 2607:f8b0:4009:801::200e ord30s31-in-x0e.1e100.net
Address 2: 172.217.4.238 ord30s31-in-f14.1e100.net
Check it by running the container:
root@labadmin-VirtualBox:/home/labadmin# docker run -it e02e811dd08f
/ # ping google.com
PING google.com (172.217.4.238): 56 data bytes
64 bytes from 172.217.4.238: seq=0 ttl=47 time=251.506 ms
64 bytes from 172.217.4.238: seq=1 ttl=47 time=245.621 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 245.621/257.113/272.586 ms
/ #
For more Info : https://robinwinslow.uk/2016/06/23/fix-docker-networking-dns/
Upvotes: 0
Reputation: 537
When you test by running the container manually you don't update the cache whith apt-get update
hence the Unable to locate package
error
But your Dockerfile example should work
Upvotes: 0