简体   繁体   English

无法(apt-get)在 docker 中安装软件包

[英]Cannot (apt-get) install packages inside docker

I installed ubuntu 14.04 virtual machine and run docker(1.11.2).我安装了 ubuntu 14.04 虚拟机并运行 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.以下解决方案我尝试过,但没有成功。

  1. restarted docker here 在这里重新启动docker

  2. run as apt-get -qq -y install curl here :same error :(这里运行apt-get -qq -y install curl :同样的错误 :(

how can i view detailed error message ?如何查看详细的错误信息? a any way to fix the issue?有什么方法可以解决这个问题?

you may need to update os inside docker before您可能需要在 docker 内部更新 os

try to run apt-get update first, then apt-get install xxx尝试先运行apt-get update ,然后apt-get install xxx

The cached result of the apt-get update may be very stale. apt-get update的缓存结果可能非常陈旧。 Redesign the package pull according to the Docker best practices:根据 Docker 最佳实践重新设计包拉取:

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/*  

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.确保由 docker 自动完成的 iptables 设置没有被您或其他应用程序无意中弄乱。 Typically, if another docker container runs with a net=host option, this can cause trouble.通常,如果另一个 docker 容器使用 net=host 选项运行,这可能会导致问题。

  • 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.图像问题:您在容器中运行的发行版不是 Ubuntu 14.04,而是构建 java:8 的发行版。 If you took the java image from official library on docker hub, you have a hierarchy of images coming initially from Debian jessie.如果您从 docker hub 上的官方库中获取了 java 图像,那么您将拥有最初来自 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.您可能希望查看此层次结构中的不同 Dockerfile,以找出 repo 设置不是您正在查看的位置。

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.对于这两种情况,要对此进行调试,我建议您在最新映像中运行一个 shell,以查看映像中的实际网络和存储库情况。 In your case在你的情况下

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

gives you a shell just before running your install maven command.在运行 install maven 命令之前为您提供一个 shell。

I am currently working behind proxy.我目前在代理后面工作。 it failed to download some dependency.它无法下载某些依赖项。 for that you have to mention proxy configuration in docker file.为此,您必须在 docker 文件中提及代理配置。 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.但是,现在我由于代理而面临运行"mvn", "dependency:resolve"困难,maven 本身阻止下载一些依赖项并且构建失败。

thanks buddies for your great support !感谢小伙伴们的大力支持!

Execute 'apt-get update' and 'apt-get install' in a single RUN instruction.在单个 RUN 指令中执行“apt-get update”和“apt-get install”。 This is done to make sure that the latest packages will be installed.这样做是为了确保安装最新的软件包。 If 'apt-get install' were in a separate RUN instruction, then it would reuse a layer added by 'apt-get update', which could have been created a long time ago.如果 'apt-get install' 在单独的 RUN 指令中,那么它会重用由 'apt-get update' 添加的层,这可能是很久以前创建的。

RUN apt-get update && \
    apt-get install -y <tool..eg: maven>

Note: RUN instructions build your image by adding layers on top of the initial image.注意:RUN 指令通过在初始镜像之上添加层来构建镜像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM