【问题标题】:Device or resource busy - Docker设备或资源繁忙 - Docker
【发布时间】:2017-09-02 07:46:49
【问题描述】:

在带有ubuntu:latest (Xenial) 映像的新 Ubuntu 14.04 机器上执行 apt-get -y upgrade 时,会引发错误:

Setting up makedev (2.3.1-93ubuntu2~ubuntu16.04.1) ...
mv: cannot move 'console-' to 'console': Device or resource busy
makedev console c 5 1 root tty 0600: failed

我在全新的 Ubuntu 14.04 上全新安装了 docker,使用以下命令:

sudo apt-get remove docker docker-engine
sudo apt-get update
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
wget -qO- https://get.docker.com/ | sudo sh
su - $USER # To logout and login

hello-world 的 Docker 运行良好:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

当我创建一个空的 docker 容器时:

docker run -it ubuntu bash

并运行以下内容:

apt-get update
apt-get install -y debconf-utils
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
apt-get update
apt-get -y upgrade

错误:

Setting up makedev (2.3.1-93ubuntu2~ubuntu16.04.1) ...
mv: cannot move 'console-' to 'console': Device or resource busy
makedev console c 5 1 root tty 0600: failed

在执行最后一个apt-get -y upgrade时引发

完整的 docker 日志开启:https://gist.github.com/alvations/ebe7175b984213d6f64a3c779ba3249e

【问题讨论】:

  • 你真的不应该在容器内调用升级 - 只需下载更新版本的基础映像。
  • 不过已经是ubuntu:latest了。
  • 对。因此,要获得更新的版本,您需要在更新图像时执行docker pull,然后执行您的docker build
  • 除了@AdrianMouat 已经说过的关于发行版升级的最佳实践:我认为升级核心库需要特殊权限(或者甚至不适用于内核)。 makedev 大概就是这样一个库。

标签: ubuntu docker device apt-get package-managers


【解决方案1】:

Docker 容器不是完整的虚拟机。它们与主机共享内核,因此某些低级操作(例如制造设备)会失败也就不足为奇了。但是,我确实注意到,尽管出现错误消息,该命令并没有失败 - 命令返回 0。我建议容器实际上按预期工作。

尽管如此,最好的答案就是不要运行apt-get upgrade。您正在使用ubuntu:latest 映像,Docker 会使用新版本保持最新。因此,不要使用apt-get upgrade 来获取新版本,而只需使用docker pull ubuntu:latest

您可以在https://github.com/docker-library/repo-info/blob/master/repos/ubuntu/remote/latest.md 此处查看latest 图像的最后更新时间。在撰写本文时,最后一次更新是在 6 周前,所以它会丢失一些更新。虽然我很失望它不是最新的,但我仍然建议不要运行upgrade,因为您可能会遇到问题并将更新的责任转移到自己身上。如果缺少重要更新,请打开一个问题。

我确实注意到debian 图像似乎保持更新,可能是因为它被用作许多官方图像的基础图像 - 如果可能,我建议使用它。

【讨论】:

  • docker pull ubuntu:latest 返回Status: Image is up to date for ubuntu:latestapt-get upgradedocker pull 之后还有很多需要升级的地方
  • 公平点。为了量化,在撰写本文时,有 8 个包已过期。
【解决方案2】:

同意其他答案/cmets apt-get -y upgrade 不如提取更新/更新的图像好。如果需要特定包但映像中已过期,则安装该特定包通常就足够了(因为将根据需要更新依赖项)。

然而,你真的没有理由不能使用apt-get -y upgrade,事实上,我认为这是一个错误,类似于但不完全相同:

https://bugs.launchpad.net/ubuntu/+source/makedev/+bug/1675163

失败的部分是在 postinst 脚本中对 MAKEDEV 的第一次调用,但这已被处理并且脚本继续。最终这意味着安装 makedev 没有当前问题。 但这可能并不总是正确的,因此可能需要在 Ubuntu 中提出一个错误才能检测到 docker 容器(不知何故)。

注意:如果你现在关心 makedev 破坏你的 docker /dev/ 目录或者想确保你摆脱安装 makedev 的任何错误情况,我链接到的错误的修复可以用于诱使安装后脚本不运行。脚本中的检查说:

# don't stomp on LXC users
if grep -q container=lxc /proc/1/environ
then
    echo "LXC container detected, aborting due to LXC managed /dev."
    exit 0
fi

因此,如果您要添加名称以容器结尾且值为 lxc 的环境变量,则检查将被触发并且不会安装新设备

docker run -ti -e "ImNotAnLXCcontainer=lxc" ubuntu

这将导致脚本退出,而不是创建一大堆 /dev/ 条目,并输出消息:

Setting up makedev (2.3.1-93ubuntu2~ubuntu16.04.1) ...
LXC container detected, aborting due to LXC managed /dev.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-29
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2022-12-03
    相关资源
    最近更新 更多