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
Docker error: Unable to locate package git
提问by Nyxynyx
I'm using an image nginx
which 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 pull
so I tried installing git
but apt
is unable to find the package:
我想做一个git pull
所以我尝试安装git
但apt
无法找到包:
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 git
from 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 update
prior 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 -y
is convenient to automatically answer yes to all the questions.
使用-y
非常方便,自动回答是肯定的所有问题。