Cannot (apt-get) install packages inside docker

Cannot (apt-get) install packages inside docker

I installed ubuntu 14.04 virtual machine and run docker(1.11.2). I try to build sample image (here).
docker file :
FROM java:8

# Install maven
RUN apt-get update
RUN apt-get install -y maven
….

I get following error:
Step 3: RUN apt-get update
–> Using cache
—>64345sdd332
Step 4: RUN apt-get install -y maven
—> Running in a6c1d5d54b7a
Reading package lists…
Reading dependency tree…
Reading state information…
E: Unable to locate package maven
INFO[0029] The command [/bin/sh -c apt-get install -y maven] returned a non-zero code:100

following solutions I have tried, but no success.

restarted docker here
run as apt-get -qq -y install curl here :same error 🙁

how can i view detailed error message ?
a
any way to fix the issue?

Solutions/Answers:

Solution 1:

you may need to update os inside docker before

try to run apt-get update first, then apt-get install xxx

Solution 2:

The cached result of the apt-get update may be very stale. Redesign the package pull according to the Docker best practices:

FROM java:8 

# Install maven
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive \
    apt-get install -y maven \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*  

Solution 3:

Based on similar issues I had, you want to both look at possible network issues and possible image related issues.

  • Network issues : you are already looking at proxy related stuff. Make sure also the iptables setup done automatically by docker has not been messed up unintentionnaly by yourself or another application. Typically, if another docker container runs with a net=host option, this can cause trouble.

  • Image issues : The distro you are running on in your container is not Ubuntu 14.04 but the one that java:8 was built from. If you took the java image from official library on docker hub, you have a hierarchy of images coming initially from Debian jessie. You might want to look the different Dockerfile in this hierarchy to find out where the repo setup is not the one you are looking at.

Related:  OpenShift V3 vs. OpenShift V2 [closed]

For both situations, to debug this, I recommand you run inside the latest image a shell to look the actual network and repo situation in your image. In your case

docker run -ti --rm 64345sdd332 /bin/bash

gives you a shell just before running your install maven command.

Solution 4:

I am currently working behind proxy. it failed to download some dependency. for that you have to mention proxy configuration in docker file. ref

but, now I facing difficulty to run "mvn", "dependency:resolve" due to the proxy, maven itself block to download some dependency and build failed.

thanks buddies for your great support !

References