apt-get not working in Dockerfile

2019-06-02 10:15发布

问题:

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.

回答1:

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


回答2:

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.



回答3:

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



回答4:

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

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

Are you working with the correct Dockerfile?



回答5:

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



回答6:

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!