Docker 构建错误 /bin/sh: 1: apt-get: 未找到

Noo*_*oon 0 ubuntu docker

我尝试构建 docker 映像,但遇到了这个问题 这是我的 dockerfile

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

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

CMD /bin/bash
Run Code Online (Sandbox Code Playgroud)

che*_*ner 5

无关的反斜杠导致前面的空格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 Code Online (Sandbox Code Playgroud)

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

RUN apt-get update && \
apt-get install -y git
Run Code Online (Sandbox Code Playgroud)

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