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 \
    3. Create the new file.
      cat <<EOF > /etc/systemd/system/docker.service.d/docker.conf
      ExecStart=/usr/bin/dockerd \$OPTIONS
  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:

    2. 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"
      myFix="--exec-opt native.cgroupdriver=cgroupfs"
      myMount="--storage-opt dm.mountopt=discard"
      myFlag="--storage-opt dm.thinpooldev=$myPool"
    3. Add the arguments to the Docker configuration file.
      echo 'OPTIONS="'$myLog $myDriver $myFix $myMount $myFlag'"' \
        >> /etc/sysconfig/docker
    4. 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, add the following flags:
      --dns= --bip=
    4. Save the file, and then close the editor.
    5. Restart the Docker service.
      systemctl restart docker 
  6. Remove a previous workaround for an NFS rpcbind issue.
    1. Remove the NFS service drop-in file, if it exists.
      test -f /etc/systemd/system/nfs-server.service.d/nfs-server.conf \
        && rm -f /etc/systemd/system/nfs-server.service.d/nfs-server.conf
    2. Reload the systemd manager configuration.
      systemctl daemon-reload
  7. 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.