5

I cannot build my image with the following Dockerfile:

FROM ubuntu

RUN apt-get -y update && apt-get -y install \
nodejs npm ssh

# cache npm install when package.json hasn't changed
WORKDIR /tmp
ADD package.json package.json
RUN npm install
RUN npm install -g pm2

RUN mkdir /sparrow
RUN cp -a /tmp/node_modules /sparrow

WORKDIR /sparrow
ADD . /sparrow/
RUN npm run build

# ssh keys
WORKDIR /root
RUN mv /sparrow/.ssh /root/

# upload js and css
WORKDIR /sparrow/build
# UPLOAD TO S3!

# go back to /sparrow
WORKDIR /sparrow

ENV NODE_ENV production
ENV NODE_PATH "./src"

EXPOSE 8000
CMD ["pm2", "start", "./bin/server.js", "--no-daemon", "-i", "0"]

Seems like it's having trouble connecting to the internet to install ubuntu packages and failing with:

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...
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.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package nodejs
E: Unable to locate package npm

Any suggestions for how to resolve or test this problem? Running on El Capitan OSX

Thanks!

Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84
  • 1
    Possible duplicate of [Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything](http://stackoverflow.com/questions/24991136/docker-build-could-not-resolve-archive-ubuntu-com-apt-get-fails-to-install-a) – Dirk Eddelbuettel Dec 08 '15 at 03:17

4 Answers4

9

This has been answered at Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything

This also affects yum and other repo mangers since we expect them to be accessible but the containers have only the network settings allowed in the host

I like to add these lines at the start of my scripts:

#DNS update: This is needed to run yum and to let the docker build process access the internet. 
RUN "sh" "-c" "echo nameserver 8.8.8.8 >> /etc/resolv.conf"

Update: From the comments below: when you move between networks say between wifi networks or between home and work the container doesn't know it's in a new network. Restarting the VM or Docker machine is the best fix.

SidJ
  • 669
  • 12
  • 29
  • 3
    Rebooting the VirtualBox VM fixed this issue on my Mac running Docker Toolbox. – ed209 Dec 29 '15 at 21:08
  • My guess is when we move between networks and the container is already running it can't pick up the new network settings. I am not sure how VirtualBox handles this situation when your host machine is on a different network AFTER the VM started. – SidJ Jan 11 '16 at 23:32
  • @ed209 You should post that as a separate answer ;) Did the trick for me too! – jessepinho Mar 16 '17 at 23:36
4

On an Ubuntu host for me the following Entry in /etc/default/docker

DOCKER_OPTS="--dns 172.21.32.182"

and then:

sudo systemctl daemon-reload
sudo systemctl restart docker

helped to fix network connection issues. Of course you need to replace 172.21.32.182 with your dns.

siddhartino
  • 341
  • 3
  • 8
1

See https://github.com/boot2docker/boot2docker/issues/451#issuecomment-65432123. What is likely happening is that your VirtualBox NAT DNS proxy has a stale route. You usually have to reboot the VM to get this working again.

Another workaround is to just have the VM use your hosts resolver (which should be updated when the DHCP hands out new name servers). Assuming your machine was named dev under Docker Machine, you can do something like:

docker-machine stop dev
VBoxManage modifyvm dev --natdnsproxy1 off --natdnshostresolver1 off
docker-machine start dev
Andy Shinn
  • 26,561
  • 8
  • 75
  • 93
  • Yesss, this works on OSX 10.9 , docker-machine docker-machine version 0.5.4, docker 1.9.1 ; thank you very much – ocramz Apr 30 '16 at 16:20
0

Docker build fails because of the warning ---> [Warning] IPv4 forwarding is disabled. Networking will not work even if you can resolve the archive.ubuntu.com Solution-

  • firewall on.
  • In my case centos7-Add the following to /etc/sysctl.conf: net.ipv4.ip_forward = 1
  • Apply the sysctl settings: sysctl -p
Tinkaal Gogoi
  • 4,344
  • 4
  • 27
  • 36