We recently announced that we've made available a set of Dockerfiles for Red Hat Software Collections. We are making these available since we think they may be useful to customers looking to build more complex application containers on top of RHEL and RHSCL. We don't intend the Dockerfiles to produce useful standalone images which you'll immediately put in production - the Docker images which these create are very simple containers which give you RHEL plus the basic set of packages from a particular RHSCL collection.
There are two different ways to get your hands on the Dockerfiles:
- From the upstream source at github
- From a new package, rhscl-dockerfiles, which we've shipped in the RHSCL channels - both for RHEL6 and RHEL7
We have Dockerfiles available for each of the following collections in RHSCL 1.2: httpd24, mariadb55, mongodb24, mysql55, nginx16, nodejs010, perl516, php54, php55, postgresql92, python27, python33, ror40, ruby193, and ruby200.
I'll walk through the second option here and demo the httpd24 collection. I'm using the docker package from the RHEL Extras channel - RHEL customers can use this to access the base images for RHEL 6 and 7. You'll need both the Extras channel and the RHSCL channel enabled to replicate this. You may also need to configure the docker service to run in your environment, for example to change the networking configuration, but it should work out of the box.
First up we build a docker image; note I tagged the image (the "
-t httpd24-el7" argument) so it's easy to refer to later.
# yum install rhscl-dockerfiles ... Installed: rhscl-dockerfiles.noarch 0:1.2-4.el7 Complete! # systemctl start docker # docker build -t httpd24-el7 /usr/share/rhscl-dockerfiles/rhel7/httpd24/ Sending build context to Docker daemon 4.608 kB Sending build context to Docker daemon Step 0 : FROM rhel7 ... Step 7 : EXPOSE 80 ---> Running in 8fb43a750ad1 ---> 5f337d2429f8 Removing intermediate container 8fb43a750ad1 Step 8 : EXPOSE 443 ---> Running in 7d406717cb8c ---> 9e658e4a8417 Removing intermediate container 7d406717cb8c Step 9 : ADD ./enablehttpd24.sh /etc/profile.d/ ---> 4e19e92e1a90 Removing intermediate container a6254b587d06 Successfully built 4e19e92e1a90 #
In that transcript I've omitted the intermediate steps in the Dockerfile, which are mostly running "yum", but the last ones I've left in The "EXPOSE" instruction exposes ports so they can be used from other contains. The last instruction drops a bash login script into the system's "profile.d" directory. This enables the SCL for a login shell. Here's a demo, running "bash -l" to get a login shell
# docker run -i -t httpd24-el7 bash -l bash-4.2# echo $X_SCLS httpd24 bash-4.2# httpd -V Server version: Apache/2.4.6 (Red Hat) Server built: Jul 18 2014 06:22:07 ... -D HTTPD_ROOT="/opt/rh/httpd24/root/etc/httpd" ... bash-4.2#
That shows we have the RHSCL version of httpd. If we did want to use that image... how to get it doing something useful? Here I'll show the RHSCL httpd running using a filesystem mounted from the host, and mapping the port out:
# mkdir /srv/www # echo 'Hello, Docker world.' > /srv/www/index.html # chcon -Rt svirt_sandbox_file_t /srv/www # docker run -d -v /srv/www:/opt/rh/httpd24/root/var/www/html -p 8080:80 httpd24-el7 scl enable httpd24 'httpd -DFOREGROUND' 76e0705a9cdfc43389262e38460b16e8d7a31a2e7fba42cfb680bb5fe301f83a # curl http://localhost:8080/ Hello, Docker world. #
There is one trick above which might not be familiar to regular Docker users: I had to apply a special SELinux label, "
svirt_sandbox_file_t", to the directory in the host system before it can be accessed from the container. More details on that in the RHEL7 container guide. Otherwise, the "
docker run" command does three things: it daemonizes (-d), and maps in the filesystem volume (-v) and port (-p). The paths are appropriate to the RHSCL httpd24 collection, and httpd itself is run under "
scl enable" so the SCL environment is set up correctly.
That's it for a quick guide. Let us know in the comments if you have use cases for RHSCL Dockerfiles which you think we should address, or combinations of SCLs which you'd like to see shipping.Last updated: September 7, 2023