Unable to install CURL on Docker Ubuntu image

I'm trying to install curl on ubuntu 14.04 in Docker image and the simple:

sudo apt-get update sudo apt-get install curl

will never work with the following output. It seems that curl installation is impossible through apt-get on this Docker image. I will be thankful for any help as I'm new to running Docker.

Err http://archive.ubuntu.com trusty InRelease Err http://archive.ubuntu.com trusty-updates InRelease Err http://archive.ubuntu.com trusty-security InRelease Err http://archive.ubuntu.com trusty Release.gpg Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com trusty-updates Release.gpg Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com trusty-security Release.gpg Could not resolve 'archive.ubuntu.com' Reading package lists... Done W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'archive.ubuntu.com'

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg Could not resolve 'archive.ubuntu.com'

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg Could not resolve 'archive.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead

Err http://archive.ubuntu.com/ubuntu/ trusty/main libkeyutils1 amd64 1.5.6-1 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty/main libidn11 amd64 1.28-1ubuntu2 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty/main librtmp0 amd64 2.4+20121230.gitdf6c518-1 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libkrb5support0 amd64 1.12+dfsg-2ubuntu5.2 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libk5crypto3 amd64 1.12+dfsg-2ubuntu5.2 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libkrb5-3 amd64 1.12+dfsg-2ubuntu5.2 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libgssapi-krb5-2 amd64 1.12+dfsg-2ubuntu5.2 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main libcurl3 amd64 7.35.0-1ubuntu2.5 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main ca-certificates all 20141019ubuntu0.14.04.1 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main krb5-locales all 1.12+dfsg-2ubuntu5.2 Could not resolve 'archive.ubuntu.com' Err http://archive.ubuntu.com/ubuntu/ trusty-security/main curl amd64 7.35.0-1ubuntu2.5 Could not resolve 'archive.ubuntu.com' E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb5support0_1.12+dfsg-2ubuntu5.2_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libk5crypto3_1.12+dfsg-2ubuntu5.2_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/keyutils/libkeyutils1_1.5.6-1_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb5-3_1.12+dfsg-2ubuntu5.2_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/libgssapi-krb5-2_1.12+dfsg-2ubuntu5.2_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libi/libidn/libidn11_1.28-1ubuntu2_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/r/rtmpdump/librtmp0_2.4+20121230.gitdf6c518-1_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/c/curl/libcurl3_7.35.0-1ubuntu2.5_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20141019ubuntu0.14.04.1_all.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/k/krb5/krb5-locales_1.12+dfsg-2ubuntu5.2_all.deb Could not resolve 'archive.ubuntu.com'

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/c/curl/curl_7.35.0-1ubuntu2.5_amd64.deb Could not resolve 'archive.ubuntu.com'

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

I tried to make a Dockerfile and reproduced the problem. Seems you are lacking dns configuration. Below I try to build a Dockerfile with basic contents (CMD tail) and tag it as trusty.

anovil@ubuntu-anovil:~/tmp/serverfault$ cat Dockerfile 
FROM ubuntu:trusty
RUN apt-get update \
  && apt-get install -y curl
CMD tail -f /dev/null

anovil@ubuntu-anovil:~/tmp/serverfault$ docker build -t trusty .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:14.04
14.04: Pulling from library/ubuntu
Digest: sha256:d3b59c1d15c3cfb58d9f2eaab8a232f21fc670c67c11f582bc48fb32df17f3b3
Status: Downloaded newer image for ubuntu:14.04
 ---> 89d5d8e8bafb
Step 2 : RUN apt-get update   && apt-get install -y curl
 ---> Using cache
 ---> 23e51481a6b8
Successfully built 23e51481a6b8

Instead of just running it, pass the dns of your choice or global dns like this:

anovil@ubuntu-anovil:~/tmp/serverfault$ docker run -d --dns=8.8.8.8 trusty  
5fe788260e6e43157fc06d991f994a6fd029624fb71dc6662024f2c118ac7577
anovil@ubuntu-anovil:~/tmp/serverfault$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
5fe788260e6e        trusty              "/bin/sh -c 'tail -f "   3 seconds ago       Up 2 seconds                            gloomy_dijkstra
anovil@ubuntu-anovil:~/tmp/serverfault$

Alternatively you could check whats the nameserver your docker container is using like this:

anovil@ubuntu-anovil:~/tmp/serverfault$ docker run -it trusty cat /etc/resolv.conf 
search xyz.com
nameserver A.B.C.D

anovil@ubuntu-anovil:~/tmp/serverfault$ docker run -it --dns=8.8.8.8 trusty cat /etc/resolv.conf 
search xyz.com
nameserver 8.8.8.8
anovil@ubuntu-anovil:~/tmp/serverfault$ 

You could clearly see the difference in the resolve.conf inside the container.

Let us know how it went.

It seems like you can't access those resources because the DNS are not configured. Check if you have access to them (ping 8.8.8.8) and then configure the DNS for the docker (adding nameserver 8.8.8.8 to /etc/resolv.conf).

Regards

Your containers don’t appear to have access to the Internet.