FROM 需要一个或三个参数 Docker

FROM requires one or three arguments Docker

我运行docker build -t imagename .

我收到以下错误:

 Step 1/1 : FROM ubuntu:14.04 
 ENV MAVEN_VERSION 3.3.9 RUN mkdir -p /usr/share/maven \ 
 && curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \ | 
 tar -xzC /usr/share/maven --strip-components=1 \
 && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn ENV MAVEN_HOME 
 /usr/share/maven VOLUME /root/.m2 CMD ["mvn"]
        **FROM requires either one or three arguments**

任何人都可以告诉我应该如何解决这个问题。我从 17.12 降级到 17.06,这样我在构建时就不会得到 Bad Response from Docker Enginer。其他人工作正常。我可以拉 运行 其他图像。我无法构建。请帮助并提出修复建议谢谢!

我的docker版本是

Docker version 17.06.2-ce, build cec0b72

Docker 信息是:

 Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 1
Server Version: 17.06.2-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.41-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: moby
ID: 3S5I:DUOJ:EBRI:PRH6:VMBJ:6H3K:OBZB:HFH7:7RSH:XEO5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 15
 Goroutines: 26
 System Time: 2018-01-15T16:10:58.5589804Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Docker 文件是:

FROM ubuntu:14.04
ENV MAVEN_VERSION 3.3.9

RUN mkdir -p /usr/share/maven \
  && curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
    | tar -xzC /usr/share/maven --strip-components=1 \
  && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven

VOLUME /root/.m2

CMD ["mvn"] 

尝试使用 A​​RG,而不是仅仅

FROM ubuntu:14.04
ENV MAVEN_VERSION 3.3.9

改为

FROM ubuntu:14.04
ARG MAVEN_VERSION=3.5.9

虽然这与 OP 遇到的问题的原因不同,但在按照教程进行操作后我遇到了完全相同的错误。

原来所说的教程在每个配置行的末尾都有注释,例如 FROM python:3 # 基础镜像

删除评论后,一切正常(结果是“#”必须在评论的开头,正如所讨论的)。

在我的例子中,这个错误是由于在 Windows 上有一个带有 CR 行结尾的 Dockerfile 引起的。转换为 CRLF 或 LF 解决了问题。