apt-get not working in Dockerfile

27.7k views Asked by At

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.

6

There are 6 answers

0
Mina Han On BEST ANSWER

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

1
codinglimo On

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?

3
Abdullah Jibaly On

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
0
user3437964 On

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

0
Vic Boudolf On

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.

0
Joseph M. Dion On

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!