Configuring Docker

Use this procedure to configure Docker.
  1. Log in as root, or as a user with superuser privileges.
  2. Create a new Docker drop-in file.
    1. Create a directory for the drop-in file, if necessary.
      test -d /etc/systemd/system/docker.service.d \
        || mkdir -p /etc/systemd/system/docker.service.d
    2. Create a backup of the drop-in file, if it exists.
      test -f /etc/systemd/system/docker.service.d/docker.conf \
        && cp -p /etc/systemd/system/docker.service.d/docker.conf \
        /etc/systemd/system/docker.service.d/docker.conf.bak
    3. Create the new file.
      cat <<EOF > /etc/systemd/system/docker.service.d/docker.conf
      [Service]
      TimeoutSec=300
      EnvironmentFile=-/etc/sysconfig/docker
      ExecStart=
      ExecStart=/usr/bin/dockerd \$OPTIONS
      TasksMax=infinity
      EOF
  3. Reload the systemd manager configuration.
    systemctl daemon-reload
  4. Configure and start the Docker service.
    1. Create a variable for the name of the Docker thin pool.

      Replace Thin-Pool-Device with the name of the thin pool device created in the previous step:

      myPool="Thin-Pool-Device"
    2. Create a variable for the master host.

      Replace Master with the virtual hostname (HA-Virtual-Name) or IPv4 address (HA-Virtual-IP) of the high-availability cluster:

      myCluster="Master"

      The value of this variable must match the value of the SERVICED_DOCKER_REGISTRY variable in /etc/default/serviced.

    3. Create variables for adding arguments to the Docker environment file. The --exec-opt argument is a workaround for a Docker issue on RHEL/CentOS 7.x systems.
      myDriver="--storage-driver devicemapper"
      myLog="--log-level=error"
      myFix="--exec-opt native.cgroupdriver=cgroupfs"
      myMount="--storage-opt dm.mountopt=discard"
      myFlag="--storage-opt dm.thinpooldev=$myPool"
      myReg="--insecure-registry=$myCluster:5000"
    4. Add the arguments to the Docker configuration file.
      echo 'OPTIONS="'$myLog $myDriver $myFix $myMount $myFlag $myReg'"' \
        >> /etc/sysconfig/docker
    5. Start or restart Docker.
      systemctl restart docker
      The startup may take up to a minute as Docker updates the storage layout.
  5. Configure name resolution in containers.
    Each time it starts, docker selects an IPv4 subnet for its virtual Ethernet bridge. The selection can change; this step ensures consistency.
    1. Identify the IPv4 subnet and netmask docker has selected for its virtual Ethernet bridge.
      ip addr show docker0 | grep inet
    2. Open /etc/sysconfig/docker in a text editor.
    3. Add the following flags to the end of the OPTIONS declaration.

      Replace Bridge-Subnet with the IPv4 subnet docker selected for its virtual bridge:

      --dns=Bridge-Subnet --bip=Bridge-Subnet/16
      For example, if the bridge subnet is 172.17.0.1, add the following flags:
      --dns=172.17.0.1 --bip=172.17.0.1/16
    4. Save the file, and then close the editor.
    5. Restart the Docker service.
      systemctl restart docker 
  6. Compare the previous version of the Docker environment file with the new version, and add any customizations for your deployment to the new version.
    diff /etc/sysconfig/docker /etc/sysconfig/docker.bak
    If you change this file, restart Docker with systemctl restart docker.