Mono in Debian 9 Containers

Running Debian 9 and need to install the mono repository? You’ll find advice for 8 that suggests using the following:

sudo apt install apt-transport-https dirmngr
sudo apt-key adv --keyserver hkp:// --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb stable-stretch main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

When it comes time to docker build, you might see the following:

Step 6/12 : RUN apt-key adv --keyserver hkp:// --recv-keys A6A19B38D3D831EF
---> Running in abbbdefb9d15
Executing: /tmp/apt-key-gpghome.GbZgRWnneE/ --keyserver hkp:// --recv-keys A6A19B38D3D831EF
gpg: cannot open '/dev/tty': No such device or address
The command '/bin/sh -c apt-key adv --keyserver hkp:// --recv-keys A6A19B38D3D831EF' returned a non-zero code: 2

Don’t despair! The following line in your Dockerfile (replacing the apt-key adv command) will get you going:

RUN curl | apt-key add -