Docker 错误:无法定位包 git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29929534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:08:49  来源:igfitidea点击:

Docker error: Unable to locate package git

gitdockerubuntuapt

提问by Nyxynyx

I'm using an image nginxwhich is based on dockerfile/ubuntu. On attaching to the docker container's shell

我正在使用nginx基于dockerfile/ubuntu. 附加到 docker 容器的外壳上

docker exec -it <container_id> /bin/bash

I want to do a git pullso I tried installing gitbut aptis unable to find the package:

我想做一个git pull所以我尝试安装gitapt无法找到包:

root@a71e45d5cd40:/# apt-get install git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package git

How can we install gitfrom that image and why is it missing?

我们如何git从该映像安装,为什么缺少它?



cat /etc/apt/sources.list

cat /etc/apt/sources.list

deb http://httpredir.debian.org/debian wheezy main
deb http://httpredir.debian.org/debian wheezy-updates main
deb http://security.debian.org wheezy/updates main
deb http://nginx.org/packages/mainline/debian/ wheezy nginx

cat /etc/apt/sources.list.d/*

cat /etc/apt/sources.list.d/*

cat: /etc/apt/sources.list.d/*: No such file or directory

apt-cache madison git

apt-cache 麦迪逊 git

N: Unable to locate package git

回答by Michael

This is happening because the apt repository is not yet updated, it is common practice to clean your apt repositories and tmp files after creating an image, which your base image is probably doing.

发生这种情况是因为 apt 存储库尚未更新,通常的做法是在创建映像后清理 apt 存储库和 tmp 文件,您的基本映像可能正在这样做。

To fix this, you are going to want to run apt-get updateprior to installing git, it is good practice to combine the update and install command at the same time to bust cache on the update if the install line changes:

要解决此问题,您需要apt-get update在安装 git 之前运行,如果安装行更改,最好同时组合更新和安装命令以破坏更新缓存:

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

Using -yis convenient to automatically answer yes to all the questions.

使用-y非常方便,自动回答是肯定的所有问题。