[英]Docker build error /bin/sh: 1: apt-get: not found
i tried to build docker image but have this problem Here is my dockerfile我试图构建 docker 镜像,但有这个问题 这是我的 dockerfile
FROM ubuntu:16.04
MAINTAINER Noon qop.box@gmail.com
RUN apt-get update && \ apt-get -y git
CMD /bin/bash
The extraneous backslash is causing the space preceding apt-get
to be treated literally, rather than just separating the command name from &&
.多余的反斜杠导致
apt-get
前面的空格按字面意思处理,而不仅仅是将命令名称与&&
分开。 The means you are trying to run a command named <space>apt-get
.这意味着您正在尝试运行名为
<space>apt-get
的命令。 Just omit the backslash.只需省略反斜杠。
# And add the install command to the second call to apt-get
RUN apt-get update && apt-get install -y git
The backslash is only necessary if you want to split the RUN
command across two lines, like反斜杠仅在您想将
RUN
命令分成两行时才需要,例如
RUN apt-get update && \
apt-get install -y git
where the backslash acts as a line continuation in the Dockerfile;其中反斜杠在 Dockerfile 中充当行的延续; it's not part of the command itself.
它不是命令本身的一部分。
As @tgogos answered in comment, you can try正如@tgogos 在评论中回答的那样,您可以尝试
RUN apt-get update && apt-get install -y git
But if you want to use multi-line, you can also use like this但是如果你想使用多行,你也可以这样使用
RUN apt-get update \
&& apt-get install -y git \
&& <other command under RUN> \
&& <and so on>
And @chepner is also right about multi-line style @chepner 对多线样式的看法也是正确的
A similar error could occur if you are on a different Unix distribution.如果您使用不同的 Unix 发行版,可能会发生类似的错误。 In my case I changed
apt-get
to apk
and that worked for me.就我而言,我将
apt-get
更改为apk
,这对我apk
。
使用conda install -c anaconda git 对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.