AlexW
AlexW

Reputation: 2591

docker - using python image, add the non-free Debian repo?

Im using a python image in docker and have added some dependencies as per the below:

RUN apt-get update -y \
    && apt-get install -y apt-utils libsasl2-dev python3-dev libldap2-dev libssl-dev libsnmp-dev snmp-mibs-downloader

I'm getting an error

E: Package 'snmp-mibs-downloader' has no installation candidate

Which after searching is because I need a non-free repo adding as per: http://installion.co.uk/debian/wheezy/non-free/s/snmp-mibs-downloader/install/index.html

I believe I need to edit /etc/apt/sources.list and add the below:

deb http://http.us.debian.org/debian jessie main contrib non-free
deb http://security.debian.org jessie/updates main contrib non-free

but how do I do that via a docker file?

Upvotes: 12

Views: 5807

Answers (3)

ascoder
ascoder

Reputation: 615

You can use any script that the other answers provide. I just made some testing with sed. This sed works for me:

sudo sed -i -e "s/ main[[:space:]]*\$/ main contrib non-free/" /etc/apt/sources.list

Basically it matches 'main', spaces and end of line. Which basically means that main is the last repo in the line. If it matches it adds the contrib and non-free at the end. If you want to test it, remove the -i to edit in-place.

The good thing of this sed it's that it doesn't repeat repos when used repeatedly. So there is no chance of having duplicate repos.

Upvotes: 0

Evan Carroll
Evan Carroll

Reputation: 1

While this is the right command,

sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list

If you're going to do this you should do this as part of the rest of your first-image,

RUN \
  sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list \
  && apt-get -q update                                              \
  && apt-get -qy dist-upgrade                                       \
  && apt-get install -qy foobar                                     \
  && foobar whatever                                                \
  && apt-get -qy --purge remove foobar                              \
  && apt-get clean                                                  \
  && rm -rf /var/lib/apt/lists

The above shows this command in the full flow with the rest of the apt stuff.

Upvotes: 18

Anis
Anis

Reputation: 3094

The same way you would do to add the non-free component to your sources.list. Edit the /etc/apt/sources.list file in your Dockerfile and replace the line that looks like:

deb http://http.us.debian.org/debian jessie main contrib

by

deb http://http.us.debian.org/debian jessie main contrib non-free

You can do that in the Dockerfile with a command like

sed -i "s#deb http://http.us.debian.org/debian jessie main contrib non-free#deb http://http.us.debian.org/debian jessie main contrib non-free#g" /etc/apt/sources.list

And same for security.debian.org.

Upvotes: 4

Related Questions