Docker错误:无法找到包git

Nyx*_*nyx 32 git ubuntu apt docker

我使用的图像nginx是基于dockerfile/ubuntu.在附加到docker容器的shell时

docker exec -it <container_id> /bin/bash
Run Code Online (Sandbox Code Playgroud)

我想做一个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
Run Code Online (Sandbox Code Playgroud)

我们如何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
Run Code Online (Sandbox Code Playgroud)

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

cat: /etc/apt/sources.list.d/*: No such file or directory
Run Code Online (Sandbox Code Playgroud)

apt-cache madison git

N: Unable to locate package git
Run Code Online (Sandbox Code Playgroud)

Mic*_*ael 93

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

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

RUN apt-get update && apt-get install -y git
Run Code Online (Sandbox Code Playgroud)

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