【问题标题】:Docker with ubtuntu:trusty and installing python-dev带有 ubuntu:trusty 和安装 python-dev 的 Docker
【发布时间】:2018-12-13 12:00:39
【问题描述】:

感谢您查看此内容。我使用https://github.com/kartoza/docker-ssh为 ssh 创建了一个 docker 映像

唯一不同的是我使用的是 ubuntu:trusty。

在此之后,我启动了容器并通过 ssh 进入容器,然后我尝试安装 python,得到以下信息:

root@a20f46f358b3:/script/docker/ubuntu-trusty# sudo apt-get -qq -y --no- 
install-recommends install python-dev
E: Unable to correct problems, you have held broken packages.
root@a20f46f358b3:/peloton/peloton/script/docker/ubuntu-trusty# sudo apt-get  
install python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python-dev : Depends: libpython-dev (= 2.7.5-5ubuntu3) but it is not going 
to be installed
          Depends: python2.7-dev (>= 2.7.5-1~) but it is not going to be 
installed
E: Unable to correct problems, you have held broken packages.

我应该使用不同的图像来创建容器吗?

没有保存的包,我通过执行验证,没有输出。

dpkg --get-selections | grep hold

有什么想法可以解决这个问题吗?非常感谢您的指导。

问候, ~灰

【问题讨论】:

    标签: python docker ubuntu apt-get


    【解决方案1】:

    在 Dockerfile 中尝试

    RUN apt-get update && sudo apt-get upgrade
    

    并检查dependecies

    apt-get install -f python2.7-dev
    

    【讨论】:

    • 你应该(几乎)永远不要在 dockerfile 中运行apt-get upgrade,你也不应该使用sudo
    • 嗨 @anthony .. 感谢您的留言,但您能分享一下为什么您永远不应该在 Dockerfile 中运行 apt-get upgrade。那是因为那应该是启动容器的一部分吗?
    • apt-get upgrade 通常会导致生成的 docker 镜像大小增加一倍,因为每个包都将被复制到多个层中。您最好的选择通常是在构建之前docker pull,以便您拥有最新的基础映像(并依靠它来获得最新的软件包)。链接的 dockerfile 中的实际错误是它们在不同的层中有 apt-get updateapt-get install,导致层缓存问题。
    【解决方案2】:

    我最终使用了 ubuntu:16.04,这对我有用。我将以下内容放在我的 Dockerfile 中

    FROM ubuntu:16.04
    

    另外,我使用以下来运行 ssh 服务器 https://docs.docker.com/engine/examples/running_ssh_service/

    希望这可以帮助其他遇到此问题的人。

    问候, ~灰

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多