繁体   English   中英

Docker 构建错误 /bin/sh: 1: apt-get: not found

[英]Docker build error /bin/sh: 1: apt-get: not found

我试图构建 docker 镜像,但有这个问题 这是我的 dockerfile

FROM ubuntu:16.04
MAINTAINER Noon qop.box@gmail.com

RUN apt-get update && \ apt-get -y git 

CMD /bin/bash

多余的反斜杠导致apt-get前面的空格按字面意思处理,而不仅仅是将命令名称与&&分开。 这意味着您正在尝试运行名为<space>apt-get的命令。 只需省略反斜杠。

# And add the install command to the second call to apt-get
RUN apt-get update && apt-get install -y git

反斜杠仅在您想将RUN命令分成两行时才需要,例如

RUN apt-get update && \
apt-get install -y git

其中反斜杠在 Dockerfile 中充当行的延续; 它不是命令本身的一部分。

正如@tgogos 在评论中回答的那样,您可以尝试

RUN apt-get update && apt-get install -y git

但是如果你想使用多行,你也可以这样使用

RUN apt-get update \
   && apt-get install -y git \
   && <other command under RUN> \
   && <and so on>

@chepner 对多线样式的看法也是正确的

如果您使用不同的 Unix 发行版,可能会发生类似的错误。 就我而言,我将apt-get更改为apk ,这对我apk

使用conda install -c anaconda git 对我有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM