If you are using a server or cloud image, you may not want to install the necessary packages to get add-apt-repository.
/etc/apt/sources.list.d/
is empty by default so you can edit only /etc/apt/sources.list
.
Without comments, OOTB docker image looks like this for me:
deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
deb http://archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted
deb http://security.ubuntu.com/ubuntu/ bionic-security universe
deb http://security.ubuntu.com/ubuntu/ bionic-security multiverse
It is unfortunate that the lines are mixed with single and multiple components and so we can't trivially filter only some lines.
something like:
sed -E -i 's/ (restricted|multiverse|universe)//;s/^deb http:..(archive|security).ubuntu.com.ubuntu. bionic(-updates|-security)?$//' /etc/apt/sources.list
will remove restricted, multiverse, and universe from the sources.list.
To keep universe but disable multiverse and restricted, use this:
sed -E -i 's/ (restricted|multiverse)//;s/ multiverse//;s/ restricted//;s/^deb http:..(archive|security).ubuntu.com.ubuntu. bionic(-updates|-security)?$//' /etc/apt/sources.list