Ubuntu – Why does this apt-get command work in one context but not the other

aptcommand linedocker

I'm trying to add the plpython package to my docker container (running an Ubunutu image) using the following command (RUN being the docker command that you can ignore if you don't know Docker):

RUN apt-get install -y postgresql-plpython-$PG_MAJOR=$PG_VERSION

However this gives the following error:

E: Unable to locate package postgresql-plpython-9.4
E: Couldn't find any package by regex 'postgresql-plpython-9.4'
INFO[0005] The command [/bin/sh -c apt-get install -y postgresql-plpython-$PG_MA
JOR=$PG_VERSION] returned a non-zero code: 100

However if I insert this same command into this part of an existing Dockerfile (i.e. I add the line postgresql-plpython-$PG_MAJOR=$PG_VERSION \, the command works.

I don't know much about apt-get, so can someone explain why the package is found in the context of the parent Dockerfile, but not my Dockerfile? What can I do to get the package to be found?

Best Answer

The Dockerfile of the base image has the following instruction:

rm -rf /var/lib/apt/lists/*

This clears the package lists downloaded by apt-get update. That's why you get the error. To solve this problem, execute apt-get update again in your Dockerfile.