本文介绍了来自守护进程的错误响应:Dockerfile 解析错误未知标志:mount的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前的问题(Docker Unknown flag --mount)面临同样的错误这是由于运行的 Docker 版本过时.我正在运行最新版本的 Docker.

There is a previous question (Docker Unknown flag --mount) facing the same error that was due to having an out-of-date version of Docker running. I have an up-to-date version of Docker running.

我有以下 Dockerfile:

FROM continuumio/miniconda3

RUN --mount=type=ssh pip install git+ssh://[email protected]/myrepo/myproject.git@develop
RUN conda install numpy
...

根据 documentation,我应该可以简单地运行 docker build --ssh default ..但是,我收到以下错误:

According to the documentation, I should be able to simply run docker build --ssh default .. However, I receive the following error:

Sending build context to Docker daemon  2.048kB
Error response from daemon: Dockerfile parse error line 3: Unknown flag: mount

docker 版本的输出:

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:39 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     true

我想在不暴露我的私有 SSH 凭据的情况下构建 Docker 映像,这似乎是受支持的方法.有人对导致问题的原因有什么想法吗?

I would like to build a Docker image without exposing my private SSH credentials, and this seemed to be the supported method. Anyone have thoughts on what's causing the issue?

推荐答案

tl;dr

Dockerfile

# syntax=docker/dockerfile:experimental
FROM continuumio/miniconda3

RUN --mount=type=ssh pip install git+ssh://[email protected]/myrepo/myproject.git@develop
RUN conda install numpy
...

注意:第一行的注释是 必需的巫术

Note: the comment on the first line is required voodoo

然后使用以下命令构建您的 docker 映像:

Then build your docker image with:

DOCKER_BUILDKIT=1 docker build --ssh default -t my_image .

有了这个,您将能够使用 RUN 指令的noreferrer">--mount 选项.

With this, you will be able to use the --mount option for the RUN directive in your Dockerfile.

此处文档中所述,ssh 转发 只有在使用 BuildKit 后端:

As found in the documentation here, ssh forwarding when building docker image is enabled only when using the BuildKit backend:

此功能仅在使用BuildKit后端.

Docker 构建支持实验性功能,例如缓存挂载、构建使用外部启用的秘密和 ssh 转发使用语法指令实现构建器.学习关于这些功能,参考 BuildKit 中的文档存储库.

Docker build supports experimental features like cache mounts, buildsecrets and ssh forwarding that are enabled by using an externalimplementation of the builder with a syntax directive. To learn aboutthese features, refer to the documentation in BuildKitrepository.

为此,您需要 Docker 18.09(或更高版本)并且您还需要使用 DOCKER_BUILDKIT=1docker build 命令code> 环境变量并使用以下 ma​​gic comment 启动您的 Docker 文件:# syntax=docker/dockerfile:experimental.

For this you need Docker 18.09 (or later) and you also need to run the docker build command with the DOCKER_BUILDKIT=1 environment variable and start your Docker file with the following magic comment : # syntax=docker/dockerfile:experimental.

您也可以编辑 /etc/docker/daemon.json 并添加:

Also you can edit /etc/docker/daemon.json and add :

{
    "experimental" : false,
    "debug" : true,
    "features": {
        "buildkit" : true
    }
}

这篇关于来自守护进程的错误响应:Dockerfile 解析错误未知标志:mount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:29