RHEL reposycn with containers

  • On your Fedora host

yum -y install subscription-manager docker-rhsubscription subscription-manager-plugin-container

subscription-manager register

subscription-manager list --available

subscription-manager attach --pool=#########################

You're going to need a redhat.repo file. You can either get one from an existing rhel system or start the rhel container run a yum update and pull the repo file from the container.

Edit your redhat.repo file changing enabled = 0 to enabled = 1 for the repos you want to sync.

Dockerfile
FROM registry.access.redhat.com/rhel7:latest
MAINTAINER zews@zews.org

COPY    list /
COPY    sync-repos.sh /
RUN     yum clean all
RUN     yum repolist
RUN     yum -y install createrepo yum-utils
RUN     groupadd -g 1000 dockeruser
RUN     useradd -ms /bin/bash -u 1000 -g 1000 dockeruser
VOLUME  ["/repos"]
CMD ["/sync-repos.sh"]
sync-repos.sh
#!/bin/bash

echo START REPOSYNC
for i in $(cat /list); do reposync -n -p /repos/ -r ${i}; done
echo END REPOSYNC
echo ...
echo START REPOMANAGE
for i in $(ls -d /repos/*/); do rm $(repomanage --keep=1 --old ${i}); done
echo END REPOMANAGE
echo ...
echo START CREATEREPO
for i in $(ls -d /repos/*/); do createrepo -v ${i}; done
echo END CREATEREPO
build.sh
#!/bin/bash

docker build --no-cache -t zews/reposync:latest .
run.sh
#!/bin/bash

docker run -it --rm --name reposync -v /srv/redhat/repos:/repos:rw zews/reposync:latest

Here's a quick and dirty script to create a repo file pointing to the local repos that have been created.

make_repofile.sh
#!/bin/bash

REPOPATH=/srv/redhat/repos
REPOFILE=local.repo

for i in $(ls -d ${REPOPATH}/*/)
do

REPONAME=`basename ${i}`

cat << EOF >> $REPOFILE
[${REPONAME}]
name=${REPONAME}
baseurl=file:///${i}
enabled=1
gpgcheck=0

EOF

done

Now let's make another docker container to serve up the repos with NGINX

Dockerfile
FROM nginx:latest
MAINTAINER zews@zews.org

COPY default.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf

VOLUME ["/usr/share/nginx/html/"]
build.sh
#!/bin/bash

docker build --no-cache -t zews/yumrepo:latest .
run.sh
docker run -it --rm --name yumrepo -p 192.168.122.1:80:80 -v /srv/redhat/repos:/usr/share/nginx/html/:rw zews/yumrepo:latest