Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Docker is installed in a Unix shell script? [duplicate]

I need to check in a shell script if Docker is installed (Ubuntu server).

I came up with this, but the syntax is not correct.

if [[ which docker && docker --version ]]; then
  echo "Update docker"
  # command
else
  echo "Install docker"
  # command
fi

I also tried if [ which docker ] && [ docker --version ]; then

like image 437
user3142695 Avatar asked Oct 04 '17 22:10

user3142695


People also ask

How can I tell if docker is installed in Unix?

To check if you have Docker installed, run command docker ps or docker info on a terminal screen to verify it is installed and running.

Where is docker installed on Linux?

Docker daemon directory By default this directory is: /var/lib/docker on Linux. C:\ProgramData\docker on Windows.

How can I check if a program exists from a bash script?

Use the command -v Command to Check if a Command Exists in Bash. The command -v is a built-in function in all POSIX systems and Bash. This function checks if a command exists as it returns the valid path for that command if it does exist and returns NULL if it does not.


1 Answers

Using suggestions from the answer in rickdenhaan's comment:

if [ -x "$(command -v docker)" ]; then
    echo "Update docker"
    # command
else
    echo "Install docker"
    # command
fi
like image 94
Christian Desserich Avatar answered Oct 13 '22 06:10

Christian Desserich