docker build failing with Could not resolve ''

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
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
RUN mv /sparrow/.ssh /root/

# upload js and css
WORKDIR /sparrow/build

# go back to /sparrow
WORKDIR /sparrow

ENV NODE_ENV production

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:

  • Docker Jenkins Image - curl: (3) Illegal characters found in URL
  • openerp-server: error: no such option: -p
  • How do you use ENV variables in CMD, on an Alpine based image?
  • How can I automatically run a docker container on/after image build?
  • Gitlab CI: Docker connect to remote MySQL via SSH Portforwarding before running tests
  • docker-compose link container of another docker-compose
  • Err trusty InRelease
    Err trusty-updates InRelease
    Err trusty-security InRelease
    Err trusty Release.gpg
      Could not resolve ''
    Err trusty-updates Release.gpg
      Could not resolve ''
    Err trusty-security Release.gpg
      Could not resolve ''
    Reading package lists...
    W: Failed to fetch
    W: Failed to fetch
    W: Failed to fetch
    W: Failed to fetch  Could not resolve ''
    W: Failed to fetch  Could not resolve ''
    W: Failed to fetch  Could not resolve ''
    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


  • How to increase base size of one docker container
  • API HOST name from env variable node js
  • Docker for Windows error: “Hardware assisted virtualization and data execution protection must be enabled in the BIOS”
  • Automatic build with Add from URL
  • Docker - understanding start/run
  • Docker in Docker permissions error
  • 4 Solutions collect form web for “docker build failing with Could not resolve ''”

    This has been answered at
    Docker build "Could not resolve ''" 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 >> /etc/resolv.conf"

    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.

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


    and then:

    sudo systemctl daemon-reload
    sudo systemctl restart docker

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

    See 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

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

    • firewall on.
    • In my case centos7-Add the following to
      /etc/sysctl.conf: net.ipv4.ip_forward = 1
    • Apply the sysctl settings:
      sysctl -p
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.