4

ANSWER: I still don't know what was really wrong but after I restarted docker and ran it again (same dockerfile, same everything), it worked fine.

I'm using Docker on Windows and my Dockerfile is

FROM ubuntu:15.04

COPY . /src

RUN apt-get update 
RUN apt-get install -y nodejs 
...etc

but when I try to build the image I get

WARN[0001] SECURITY WARNING: You are building a Docker image from Windows against a Linux Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories

...

Step 3: RUN apt-get -y update
 --> Using cache
 --->ccd4120f98dd
Removing intermediate container 255796bdef29
Step 4: RUN apt-get install -y nodejs
 ---> Running in f6c1d5a54c7a
Reading package lists...
Reading dependency tree...
Reading state information...
E: Unable to locate package nodejs
INFO[0029] The command [/bin/sh -c apt-get install -y nodejs] returned a non-zero code:100

apt-get works but when I try to put other apt-get install lines in those don't work either so it doesn't seem to be a problem with.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Mina Han
  • 671
  • 2
  • 10
  • 17
  • FYI: you should never install your dependencies after copying over the source code. This will completely break docker's image cache any time you modify your code. – Abdullah Jibaly Jun 16 '15 at 03:46
  • I note that the line in the output you cite is not the same as the line in the Dockerfile (no `-y`); are you sure you are building from the correct Dockerfile? – Adrian Mouat Jun 16 '15 at 07:11
  • Yeah I am -- typoed the error message – Mina Han Jun 16 '15 at 23:17
  • I found that restarting docker.service and docker.socket worked for me. This if this command fails then docker itself is not able to access the internet: sudo docker run busybox nslookup google.com – mark sabido Jun 30 '23 at 10:11

6 Answers6

10

I had to put this as an answer since I can't format at all inside a comment

There should be more output describing what went wrong. Try running these steps iteratively inside a temporary container:

docker run --rm -it ubuntu:15.04 bash -l
apt-get update
apt-get install -y nodejs

Does that give you more information on what is breaking?

UPDATE

Try this and iterate on it:

FROM ubuntu:15.04
RUN apt-get update && apt-get install -y nodejs
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
  • Hm yeah those work fine but I still get the same errors when trying to build the image :/ – Mina Han Jun 16 '15 at 22:58
  • If those work then there's something wrong with your Dockerfile syntax. Try creating a brand new Dockerfile and just add the 2 lines I added in the answer. – Abdullah Jibaly Jun 16 '15 at 23:06
  • This might conflict with some SO requirements. But it helps! It's a generic answer and a help to people to help themselves.. Thank you! – pico_prob Dec 17 '21 at 18:05
5

I separated the two lines:

RUN apt-get update
RUN apt-get install -y nodejs

Found the issue was with apt-get udpate.

Tried what Abulla suggested, apt-get update worked fine.

Deleted and retyped the RUN apt-get update line in my Dockerfile, and everything worked.

Vic Boudolf
  • 134
  • 1
  • 11
3

I restarted docker and tried again and now it works fine.

Mina Han
  • 671
  • 2
  • 10
  • 17
0

I try your code

FROM ubuntu:15.04

COPY . /src

RUN apt-get update &&  
RUN apt-get install -y nodejs 

And for me everything works correctly

enter image description here

When I remove the -y flag I have the same problem

FROM ubuntu:15.04

COPY . /src

RUN apt-get update
RUN apt-get install nodejs

enter image description here

Are you working with the correct Dockerfile?

codinglimo
  • 707
  • 2
  • 6
  • 17
0

Be sure that you use the correct Dockerfile. If yes try with an other image.

user3437964
  • 107
  • 1
  • 5
0

I had the same issue and Ubuntu Xenial and the problem was due to a dnsmaq server running on my host machine.

The solution was to disable this server by commenting the dns=dnsmasq line in /etc/NetworkManager/NetworkManager.conf and perform a restart:

sudo service network-manager restart

Hope this help!

Gustavo Morales
  • 2,614
  • 9
  • 29
  • 37
Joseph M. Dion
  • 356
  • 3
  • 7