0

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?

2
  • 1
    Those npm install and composer install commands seems like they should normally be run in your image's Dockerfile, not via a debugging interface like docker exec. Do you have Dockerfiles for your Javascript and PHP applications that you could docker build?
    – David Maze
    Oct 23, 2021 at 19:33
  • Can you place this command echo $PATH right after #!/bin/bash and and before first docker command and share these 2 output. Your PATH even may be changed due to your first source command.
    – Truong Hua
    Oct 24, 2021 at 4:18

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.