我对 docker 相当陌生,正在尝试通过编写自己的镜像来学习,并且目前正在阅读 Docker 的实际操作(ISBN:1633430235)
在我自己的代码和书中的示例(第 146 页)中,我想通过 dockerfile 安装 git。
My code:
# set base image
FROM ubuntu:18.04
# author
MAINTAINER me
############## Begin installation ##########################
# update and upgrade
RUN apt-get update
RUN apt-get upgrade
# install git
RUN apt-get install -y git
***rest of code omitted***
书籍代码:
#An example Dockerfile for installing Git on Ubuntu
FROM Ubuntu:latest
MAINTAINER "dockerinac[email protected] /cdn-cgi/l/email-protection"
RUN apt-get install -y git
ENTRYPOINT ["git"]
但是,在这两种情况下,我都遇到了无法使用非零代码定位包的错误:
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package git
The command '/bin/sh -c apt-get install -y git' returned a non-zero code: 100
到目前为止我已经尝试过了。
1) 将 apt-get update 和 apt-get Upgrade 制作为单个命令。当我这样做时,它此时失败了。
2) 在安装 git 之前安装 apt-transport-https,如下所述:
apt-get update' 返回一个非零代码:100 https://stackoverflow.com/questions/38002543/apt-get-update-returned-a-non-zero-code-100
这将成功下载,但一旦再次安装 git,我就会得到同样的错误。
这
3)按照教程https://docs.docker.com/engine/reference/builder/#dockerfile-examples https://docs.docker.com/engine/reference/builder/#dockerfile-examples。尽管这是不同的,但它仍然安装 x11 服务器,但安装时也会失败。
4)根据堆栈溢出的另一个答案,无法在 docker Ubuntu 映像中安装软件包 https://stackoverflow.com/questions/27273412/cannot-install-packages-inside-docker-ubuntu-image我尝试安装curl。
所有这些方法,除了第一个之外,让我在尝试安装软件时更新和升级只会失败。如果我从运行 docker 的机器上的终端更新、升级、安装,我也没有问题。
任何有关如何纠正此问题的建议将不胜感激。