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
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.
Docker daemon directory By default this directory is: /var/lib/docker on Linux. C:\ProgramData\docker on Windows.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With