2

I am fairly new to docker and am trying to learn by writing my own images and, for now, reading Docker in action (ISBN: 1633430235)

In both my own code and an example from the book (pg 146) I would like to install git via a dockerfile.

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***

Books code:

#An example Dockerfile for installing Git on Ubuntu
FROM Ubuntu:latest
MAINTAINER "dockerinaction@allgeek.com"
RUN apt-get install -y git
ENTRYPOINT ["git"]

However, in both I am getting an unable to locate package eror with a none-zeero code:

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

So far I have tried.

1) Making apt-get update and apt-get upgrade into a single command. When I do this it fails at this point.

2) Installing apt-transport-https before installing git, as described here:

apt-get update' returned a non-zero code: 100

This will succeed in downloading but as soon as it gets to installing git again, I get the same error. This

3) Following the tutorial on https://docs.docker.com/engine/reference/builder/#dockerfile-examples. Although this is different it still installs the x11 server, again this also fails at installation.

4) Following another answer on stack overflow, Cannot install packages inside docker Ubuntu image I have tried to install curl.

Al these methods, with the exception of the first, let me update & upgrade only to fail once I try to install software. I also have no issues if I am updating, upgrading, installing from a terminal on the machine I am running docker from.

Any advice as to how I can rectify this would be greatly appreciated.

Boots
  • 43
  • 2
  • 9
  • 1
    I've just tried your exact Dockerfile and I got no error. Something you could try (suggested here https://stackoverflow.com/a/42981752/3477163) is to update and install in the same RUN command, e.g. `RUN apt-get update && apt-get install -y git`. You shouldn't need `apt-get upgrade` as that upgrades versions of installed packages (ref: https://askubuntu.com/a/94104) – supremebeing7 Aug 08 '18 at 17:14
  • 1
    I have removed upgrade. I'm not even sure why I have been doing that, only that I was told many moons ago to do it when I first install linux. I have just done it as habit ever since. It is still not working, however I am wondering if it is my creaky old computer/network as it is working for others. – Boots Aug 09 '18 at 08:05

2 Answers2

4

Execute 'apt-get update' and 'apt-get install' in a single RUN instruction. This is done to make sure that the latest packages will be installed. If 'apt-get install' were in a separate RUN instruction, then it would reuse a layer added by 'apt-get update', which could have been created a long time ago.

RUN apt-get update && \
    apt-get install -y git-core

Note: RUN instructions build your image by adding layers on top of the initial image.

Nikita Jain
  • 669
  • 8
  • 11
1

Try

FROM ubuntu:18.04
RUN \
  apt-get update \
  && apt-get install -y \
    git-core

I'm not sure, but emptylines in Dockerfile was problem

lojza
  • 1,823
  • 2
  • 13
  • 23
  • Thank you, It still is not working, I'm thinking it may be my computer and/or network as it is working for others. I will try again on the weekend with a more modern computer on and not on my work network. I will mark as answered if it works. – Boots Aug 09 '18 at 08:08