How Do You Know If Your Linux Server Can Support a Docker Installation?

Problem scenario
You want to install Docker on Linux.  How do you determine if the VM or physical server with Linux meets the minimum requirements for installing Docker?

Solution
Run this script:

#!/bin/bash
# Written by continualintegration.com
echo "This will test if your Linux server is ready for Docker."
i=0;

os=$(uname -m | grep -i x)
if [ -z "$os" ];
then
  echo "*** FAILURE ***"
  echo "The OS is 32 bit.  It will not work for Docker."
  i=$((i+1))
  echo "Proceeding to next test"
else
  echo "The OS is 64 bit"
fi

a=$(uname -r)
b=$(echo $a | awk -F  "." '/1/ {print $1}')
c=$(echo $a | awk -F  "." '/1/ {print $2}')
if [ $b -lt 3 ]
then
  echo "Kernel is not high enough"
  i=$((i+1))
else  #This is evaluated if Kernel is 3.x or 4.x or higher
  if [ $b -eq 3 ]
  then
    if [ $c -lt 10 ]
    then
      echo "*** FAILURE ***"
      echo "Kernel is not high enough"
      echo "Proceeding to next test"
      i=$((i+1))
    else
      echo "Kernel appears high enough."
    fi
  else
    echo "Kernel appears high enough."
  fi
fi

d=$(iptables -V | awk -F  "." '/1/ {print $2}')
if [ $d -ge 4 ]

then
  echo "IP tables is high enough"
else
  echo "*** FAILURE ***"
  echo "IP tables is not high enough."
  echo "Proceeding to next test"
  i=$((i+1))
fi

p=$(which ps)
if [ -z "$p" ];
then
  echo "*** FAILURE ***"
  echo "You do not have an executable ps command.  Install procps or something else."
  echo "Docker needs an executable ps command."
  echo "Proceeding to next test"
  i=$((i+1))
else
  echo "You have an executable ps command."
fi

f=$(xz --version | grep xz | awk '{print $4}' | awk -F  "." '{print $1}')
g=$(xz --version | grep xz | awk '{print $4}' | awk -F  "." '{print $2}')
if [ $f -ge 5 ]
then
  echo "The version of xz utils is high enough"
  echo "Docker test script is complete."
  echo $i " tests/checks failed."
  if [ $i -eq 0 ]
  then
    echo "Docker can be installed as long as your OS has 'a properly mounted cgroups hierarchy' taken from https://docs.docker.com/engine/installation/binaries/#install-daemon-and-client-binaries-on-linux"
  fi
  exit
fi

if [ $f -eq 4 -a $g -ge 7 ]
then
  echo "The version of xz utils is high enough"
else
  echo "*** FAILURE ***"
  echo "The version of xz utils is not high enough."
  i=$((i+1))
  echo "Docker test script is complete."
  echo $i " tests/checks failed."
  if [ $i -eq 0 ]
  then
    echo "Docker can be installed as long as your OS has 'a properly mounted cgroups hierarchy' taken from https://docs.docker.com/engine/installation/binaries/#install-daemon-and-client-binaries-on-linux"
  fi
fi

# If you are interested in a list of Docker books, see this link.
# If you want instructions for installing Docker in different public clouds or on different distros of Linux, see this posting.
# For a very different script that does something similar, you may want to see this one on GitHub.

Leave a comment

Your email address will not be published.