【问题标题】:Jenkinsfile custom docker container "could not find FROM instruction"Jenkinsfile 自定义 docker 容器“找不到 FROM 指令”
【发布时间】:2018-12-13 04:45:14
【问题描述】:

我刚刚开始使用 Jenkinsfiles 和 Docker,如果这是显而易见的事情,我们深表歉意。

我有一个包含 Dockerfile 和 Jenkins 文件的仓库。

Dockerfile 只是通过添加几个依赖项和构建工具来扩展基本 Ubuntu 映像 (ubuntu:trusty)。

Jenkinsfile 目前只为我构建 Docker 容器:

node('docker') {
stage "Prepare environment"
    checkout scm
    docker.build('build-image')
}

当我运行 Jenkins 构建时,输出日志显示 Docker 容器正在成功创建,但就在它应该成功完成之前,我得到:

Successfully built 04ba77c72c74
[Pipeline] dockerFingerprintFrom
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
ERROR: could not find FROM instruction in /home/emackenzie/jenkins/workspace/001_test-project_PR-1-ROWUV6YLERZKDQWCAGJK5MQHNKY7RJRHC2TH4DNOZSEKE6PZB74A/Dockerfile
Finished: FAILURE

我一直无法找到任何关于为什么我从互联网上收到此错误的指导,因此我们将不胜感激任何帮助


Dockerfile:

FROM    ubuntu:trusty
MAINTAINER Ed Mackenzie

# setup apt repos
RUN echo "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" >> /etc/apt/sources.list \
&& echo "deb-src http://archive.ubuntu.com/ubuntu/ trusty multiverse" >> /etc/apt/sources.list \
&& apt-get update

# python
RUN apt-get install -y python python-dev python-openssl

【问题讨论】:

    标签: jenkins docker dockerfile jenkinsfile


    【解决方案1】:

    这是因为您的FROM 行使用制表符代替空格,而不是空格。这是 Jenkins CI Docker 工作流插件中的一个错误,它要求该行以 FROM 开头,后跟一个空格。

    来自 Github 上的 jenkinsci/docker-workflow-plugin 来源:

    String fromImage = null;
    
    // ... other stuff
    
    if (line.startsWith("FROM ")) {
        fromImage = line.substring(5);
        break;
    }
    
    // ... other stuff ...
    
    if (fromImage == null) {
        throw new AbortException("could not find FROM instruction in " + dockerfile);
    }
    

    如果您使用空格而不是制表符,它应该可以正常工作。

    【讨论】:

      【解决方案2】:

      我刚遇到同样的问题,这是一个类似的解决方案。检查文件是否在文件开头使用BOM 进行编码(这可以使用 Notepad++ 之类的东西来完成)。如果是这样,请在没有标记的情况下保存它,插件将停止抱怨。

      【讨论】:

        【解决方案3】:

        错误可以通过将“from”语句更改为“FROM”来解决

        【讨论】:

        • 您能否展示一个失败/通过案例来支持您的答案?
        • 可以确认为我解决了这个问题。
        猜你喜欢
        • 2018-12-08
        • 2017-07-10
        • 2017-10-01
        • 2016-05-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多