Docker error: Unable to locate package git

帅比萌擦擦* 提交于 2019-12-04 08:51:23

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/29929534/docker-error-unable-to-locate-package-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!