Docker 错误:无法定位包 git [英] Docker error: Unable to locate package git

查看:30
本文介绍了Docker 错误:无法定位包 git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我们如何从该映像安装 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

推荐答案

这是因为 apt 存储库尚未更新,通常的做法是在创建映像后清理 apt 存储库和 tmp 文件,这是您的基础映像可能正在做.

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.

为了解决这个问题,你需要在安装 git 之前运行 apt-get update,同时结合更新和安装命令来破坏缓存是一个很好的做法如果安装行更改,请更新:

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

使用 -y 可以方便地自动对所有问题回答是".

Using -y is convenient to automatically answer yes to all the questions.

这篇关于Docker 错误:无法定位包 git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆