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…)
2
Answers
Just use
printf
and run this command as single line:Where
LDIR
is an argument and docker build process should be run like:Using the text editor of your choice, create the file on your local system. Remove the word
sudo
from 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
RUN
it.But! If you look at what the script actually does, it just writes a file into
/etc/yum.repos.d
with aLDIR
placeholder 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
COPY
that 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 root
to switch back); you do not need generallysudo
in Docker at all, and can just deletesudo
where it appears in these instructions.