Home > Mobile >  Executing docker from terminal directly works fine but not when executed from inside a .sh script?
Executing docker from terminal directly works fine but not when executed from inside a .sh script?

Time:10-25

I am on ubuntu 20.04 I installed docker using sudo snap install docker now when I run directly from the terminal (terminal installed with ubuntu) docker command it works fine but when I execute a .sh script from the terminal using either bash ./script.sh or ./script.sh I am getting an error docker: command not found.

This is the script:

#!/bin/bash
source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/env.sh

docker run -e "NODE_ENV=dev" -it --rm --name my-npm-2 -v $PROJECT_HOME/code:/var/www/html/code -w /var/www/html/code node:14 npm install

docker run -e "NODE_ENV=dev" -it --rm --name my-npm -v $PROJECT_HOME/code/web:/var/www/html/code/web -w /var/www/html/code/web node:14 npm install


$SCRIPT_HOME/buildjs_dev.sh

docker exec project_php sudo php -d memory_limit=-1 /usr/local/bin/composer install --working-dir=/var/www/html/code


docker exec project_php chown -R www-data:www-data /var/www/html/code/var/cache
docker exec project_php chown -R www-data:www-data /var/www/html/code/var/log

I am new to linux in general and I don't know if the problem is with the script itself or why isn't it recognizing docker?

CodePudding user response:

You are defining a source file at the start of your script which might be changing the PATH variable. Try by either commenting the source line or calling the docker command with full path.

  • Related