简体   繁体   English

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

[英]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.

相关问题 错误:服务 'ubuntu' 未能构建:命令 '/bin/sh -c apt-get update - ERROR: Service 'ubuntu' failed to build: The command '/bin/sh -c apt-get update docker 使用 apt-get 构建缓存破坏 - docker build cache busting with apt-get 命令 '/bin/sh -c apt-get update &amp;&amp; apt-get upgrade' 返回一个非零代码:1 - The command '/bin/sh -c apt-get update && apt-get upgrade' returned a non-zero code: 1 Docker 构建期间第二次 apt-get 更新后 Ubuntu 21.04 中的 GPG 错误 - GPG error in Ubuntu 21.04 after second apt-get update during Docker build 尝试构建 docker 映像时无法获取错误(运行 apt-get 更新时) - Failed to Fetch error when trying to build docker image (while RUN apt-get update) bash:apt-get:找不到命令(在 ubuntu docker 图像上) - bash: apt-get: command not found (on ubuntu docker image) Docker构建apt-get更新无法通过403获取 - Docker build apt-get update failed to fetch with a 403 Docker 图像错误:“/bin/sh: 1: [python,: not found” - Docker image error: "/bin/sh: 1: [python,: not found" 构建 Docker Image 时关于“apt-get update”的错误 - Error about "apt-get update" when building a Docker Image Dockerfile Image命令&#39;/ bin / sh -c apt-get install -y mysqld-server&#39;返回了非零代码:100 - Dockerfile Image The command '/bin/sh -c apt-get install -y mysqld-server' returned a non-zero code: 100
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM