【问题标题】:Can't build Dockerfile on Ubuntu Server无法在 Ubuntu 服务器上构建 Dockerfile
【发布时间】:2021-04-26 20:27:09
【问题描述】:

我正在开发一个 python 项目,在本地 Windows 上工作时,我在 Ubuntu 服务器上遇到了这个问题。当尝试运行mkdir 指令时,它会在第二步中停止。看来我无法运行典型的 Ubuntu 指令(apt-get clean、apt-get update)

Dockerfile

FROM python:3

RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install --upgrade pip==20.0.2 && pip install -r requirements.txt
COPY . /code/

输出错误

OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:297: applying cgroup configuration for process caused \"mountpoint for devices not found\"": unknown

【问题讨论】:

  • 我也有类似的问题。重新启动我的机器在短时间内解决了它。卸载 Docker 并重新安装有帮助吗?

标签: python docker dockerfile


【解决方案1】:

你能运行 Docker hello-world 镜像吗?如果不是,这可能表明您的安装/配置有问题

$ docker run hello-world

有关安装后步骤的更多信息,请访问here。否则,第一个选择是尝试重新启动 Docker

$ sudo systemctl restart docker

Docker 守护进程必须在后台以 root 权限运行,在新安装的机器上未完全应用更新的守护进程组权限之前,我遇到过问题。重新启动守护程序,或注销并登录可能会解决此问题。

此外,当您在 Dockerfile 中声明 WORKDIR 时,如果该路径尚不存在,则会自动创建该路径。一旦你设置了你的WORKDIR,如果可能的话,你所有的路径都可以并且应该是相对于它的。知道了这一点,我们就可以简化Dockerfile了

FROM python:3

WORKDIR /code
COPY requirements.txt .
RUN pip install --upgrade pip==20.0.2 && pip install -r requirements.txt
COPY . .

这可能足以解决您的问题。根据我的经验,Docker 构建回溯有时可能相当模糊,但听起来该特定错误可能源于创建目录的尝试失败,无论是主机上的权限问题还是容器内的语法问题。

【讨论】:

  • 感谢@vulpxn,无法运行 hello-world 命令。我完全卸载了 docker 并再次安装,现在看来它可以工作了。令我惊讶的是,几天前我部署了一个具有类似 Dockerfile 的 python 项目,它运行良好,并且没有修改任何有关 docker 安装的内容,这种尝试构建一个不同的项目但类似的项目是不允许的......
【解决方案2】:

我通过(重新)安装 apt 而不是 snap 解决了这个问题:

sudo snap remove docker
sudo apt install docker-io

测试(现在工作):

sudo docker run hello-world

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2017-12-04
    • 2019-10-19
    • 2023-03-15
    • 2020-05-16
    相关资源
    最近更新 更多