Creating a docker Base Image

I have a private Linux distribution (based on redhat7).
I have an ISO file which holds the installation of that distribution, which can be used to install the OS on a clear system only.
I have some programs I would like to run as images on docker, each program on a different image.
Each program can only run on my Linux environment and so I am looking for a way to create the appropriate images, so they can be ran under docker.

I tried following Solomon instructions here:

  • “CMD ['/home/user/']” in docker file doesn't work with docker-compose
  • Tornado websocket in docker (net::ERR_CONNECTION_REFUSED)
  • Kong Api's and Plugins are getting removed after kong docker container start and stop
  • Gitlab CI Runner | Custom mysql conf
  • Not able to connect with host interface service inside docker container
  • Are there disadvantages when running a docker base image that differs from my distribution?
    • mkdir rootfs
    • mount -o loop /path/to/iso rootfs
    • tar -C rootfs -c . | docker import – rich/mybase

    But I don’t know how to proceed. I can’t run any command since the machine isn’t running yet (no /bin/bash/ etc.)
    How can I open the installation shell?

    Is there a better way to run programs via docker on a private Linux distribution?
    (Just to be clear, the programs can run only on that specific OS and that OS can only be installed on a clear machine. Not sure if I need a base image but I’d like to run these programs with Docker and that is possible only over this OS)

    I ran into many questions like mine (like this) but I couldn’t find answer that helped me.

  • Docker container doesn't start, showing as 'Exited n seconds ago'
  • Can't discover docker container on user defined network
  • Dealing with the issue of embedded tomcat's port numbers when scaling the web container in a Heroku-like cloud
  • Gracefully Stopping Docker Containers
  • Will single docker container scale automatically on Amazon's EC2?
  • Docker + Django + MySQL - End of list of non-natively partitioned tables
  • 2 Solutions collect form web for “Creating a docker Base Image”


    Server A where the ISO will be mount
    Server R your private repositoy
    Server N where container will be run
    All server can connect to server R.

    How to

    1. build a base image as mentioned in your OP (named base/myimage)
    2. Push the image to your private repository

    3. Create application images from your base base/myimage then push them to your private repo

    4. From Server N, run the application image

      docker run application/myapp

    This script is from the official Docker contrib repo. It’s used to create CentOS images from scratch. It should work with any Redhat/Centos based system and gives you plenty of control over the various steps. Anything beyond that you can then modify post-base-image through a Dockerfile.

    The file is here

    #!/usr/bin/env bash
    # Create a base CentOS Docker image.
    # This script is useful on systems with yum installed (e.g., building
    # a CentOS image on CentOS).  See contrib/ for a way
    # to build CentOS images on other systems.
    usage() {
        cat <<EOOPTS
    $(basename $0) [OPTIONS] <name>
      -p "<packages>"  The list of packages to install in the container.
                       The default is blank.
      -g "<groups>"    The groups of packages to install in the container.
                       The default is "Core".
      -y <yumconf>     The path to the yum config to install packages from. The
                       default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
        exit 1
    # option defaults
    if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then
        alias yum=dnf
    while getopts ":y:p:g:h" opt; do
        case $opt in
                echo "Invalid option: -$OPTARG"
    shift $((OPTIND - 1))
    if [[ -z $name ]]; then
    target=$(mktemp -d --tmpdir $(basename $0).XXXXXX)
    set -x
    mkdir -m 755 "$target"/dev
    mknod -m 600 "$target"/dev/console c 5 1
    mknod -m 600 "$target"/dev/initctl p
    mknod -m 666 "$target"/dev/full c 1 7
    mknod -m 666 "$target"/dev/null c 1 3
    mknod -m 666 "$target"/dev/ptmx c 5 2
    mknod -m 666 "$target"/dev/random c 1 8
    mknod -m 666 "$target"/dev/tty c 5 0
    mknod -m 666 "$target"/dev/tty0 c 4 0
    mknod -m 666 "$target"/dev/urandom c 1 9
    mknod -m 666 "$target"/dev/zero c 1 5
    # amazon linux yum will fail without vars set
    if [ -d /etc/yum/vars ]; then
        mkdir -p -m 755 "$target"/etc/yum
        cp -a /etc/yum/vars "$target"/etc/yum/
    if [[ -n "$install_groups" ]];
        yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
            --setopt=group_package_types=mandatory -y groupinstall $install_groups
    if [[ -n "$install_packages" ]];
        yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
            --setopt=group_package_types=mandatory -y install $install_packages
    yum -c "$yum_config" --installroot="$target" -y clean all
    cat > "$target"/etc/sysconfig/network <<EOF
    # effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target".
    #  locales
    rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}
    #  docs and man pages
    rm -rf "$target"/usr/share/{man,doc,info,gnome/help}
    #  cracklib
    rm -rf "$target"/usr/share/cracklib
    #  i18n
    rm -rf "$target"/usr/share/i18n
    #  yum cache
    rm -rf "$target"/var/cache/yum
    mkdir -p --mode=0755 "$target"/var/cache/yum
    #  sln
    rm -rf "$target"/sbin/sln
    #  ldconfig
    rm -rf "$target"/etc/ "$target"/var/cache/ldconfig
    mkdir -p --mode=0755 "$target"/var/cache/ldconfig
    for file in "$target"/etc/{redhat,system}-release
        if [ -r "$file" ]; then
            version="$(sed 's/^[^0-9\]*\([0-9.]\+\).*$/\1/' "$file")"
    if [ -z "$version" ]; then
        echo >&2 "warning: cannot autodetect OS version, using '$name' as tag"
    tar --numeric-owner -c -C "$target" . | docker import - $name:$version
    docker run -i -t --rm $name:$version /bin/bash -c 'echo success'
    rm -rf "$target"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.