I'm following installation instructions for RedhawkSDR, which rely on having a Centos7 OS. Since my machine uses Ubuntu 22.04, I'm creating a Docker container to run Centos7 then installing RedhawkSDR in that.
One of the RedhawkSDR installation instructions is to create a file with the following command:
cat<<EOF|sed 's@LDIR@'`pwd`'@g'|sudo tee /etc/yum.repos.d/redhawk.repo
[redhawk]
name=REDHAWK Repository
baseurl=file://LDIR/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhawk
EOF
How do I get a Dockerfile to execute this command when creating an image?
(Also, although I can see that this command creates the file /etc/yum.repos.d/redhawk.repo, which consists of the lines from [redhawk] to gpgkey=...., I have no idea how to parse this command and understand exactly why it does that...)
Using the text editor of your choice, create the file on your local system. Remove the word
sudofrom it; give it an additional first line#!/bin/sh. Make it executable usingchmod +x create-redhawk-repo.Now it is an ordinary shell script, and in your Dockerfile you can just
RUNit.But! If you look at what the script actually does, it just writes a file into
/etc/yum.repos.dwith aLDIRplaceholder replaced with some other directory. The filesystem layout inside a Docker image is fixed, and there's no particular reason to use environment variables or build arguments to hold filesystem paths most of the time. You could use a fixed path in the fileand in your Dockerfile, just
COPYthat file in as-is, and make sure the downloaded package archive is in that directory. Adapting the installation instructions:Remember that, in a Dockerfile, you are root unless you've switched to another
USER(and in that case you can useUSER rootto switch back); you do not need generallysudoin Docker at all, and can just deletesudowhere it appears in these instructions.