Docker错误:无法找到包git [英] Docker error: Unable to locate package git
问题描述
我使用基于 dockerfile / ubuntu
的图像 nginx
。在附加到docker容器的shell上
docker exec -it< container_id> / bin / bash
我想做一个 git pull
所以我尝试安装 git
但 apt
无法找到该软件包:
root @ a71e45d5cd40:/#apt-get install git
阅读包列表...完成
构建依赖关系树
阅读状态信息...完成
E:无法找到包git
我们如何从该图像中安装 git
,为什么会丢失?
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/* :没有这样的文件或指示ry
apt-cache madison git
N:无法找到包git
这是因为apt存储库尚未更新,通常的做法是在创建一个映像之后清理您的apt存储库和tmp文件,这些基本映像可能正在进行。 / p>
要解决这个问题,您需要在安装git之前运行 apt-get update
,这很好如果安装行更改,则同时结合更新和安装命令来实现对更新的缓存:
RUN apt - 更新&&& apt-get install -y git
使用 -y
自动回答所有问题的答案。
I'm using an image nginx
which is based on dockerfile/ubuntu
. On attaching to the docker container's shell
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:
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?
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/*: No such file or directory
apt-cache madison git
N: Unable to locate package git
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.
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:
RUN apt-get update && apt-get install -y git
Using -y
is convenient to automatically answer yes to all the questions.
这篇关于Docker错误:无法找到包git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!