0

Im not sure why but I cant seem to run this script inside of the docker container from the host system

on the host im executing this code in a shell script

#!/bin/bash

Docker_wordpress_status_check () {
mysql_docker_status=$(docker container ls | grep -E 'docker_image_name|dockerwordpressmaster_wp-fpm_1')
if [[ "$mysql_docker_status" ]]; then
echo "checking to see if wordpress exists"
wget https://s3/wordpress_staging_to_production_image_fixer.sh
chmod +x wordpress_staging_to_production_image_fixer.sh
docker cp wordpress_staging_to_production_image_fixer.sh dockerwordpressmaster_wp-fpm_1:/var/www/html/wordpress_staging_to_production_image_fixer.sh
docker exec -it dockerwordpressmaster_wp-fpm_1 sh -c "./wordpress_staging_to_production_image_fixer.sh"
fi
}

Docker_wordpress_status_check

This script works fine for the most part and I can even see the file in the correct directory this being

/var/www/html/

and I can clearly see that the file exists inside of the container

docker exec -it dockerwordpressmaster_wp-fpm_1 sh
/var/www/html # ls -l | grep wordpress_staging_to_production_image_fixer.sh
-rwxr-xr-x    1 500      500            898 Dec 26 17:31 
wordpress_staging_to_production_image_fixer.sh

however when I try to execute the script from within the container

docker exec dockerwordpressmaster_wp-fpm_1 sh ./var/www/html/wordpress_staging_to_production_image_fixer.sh

sh: can't open './var/www/html/wordpress_staging_to_production_image_fixer.sh'

docker exec dockerwordpressmaster_wp-fpm_1 "sh" -c "/var/www/html/wordpress_staging_to_production_image_fixer.sh"

sh: /var/www/html/wordpress_staging_to_production_image_fixer.sh: not found

docker exec dockerwordpressmaster_wp-fpm_1 sh -c wordpress_staging_to_production_image_fixer.sh

sh: wordpress_staging_to_production_image_fixer.sh: not found

docker exec dockerwordpressmaster_wp-fpm_1 bash ./var/www/html/wordpress_staging_to_production_image_fixer.sh

bash: ./var/www/html/wordpress_staging_to_production_image_fixer.sh: No such file or directory

I'm not quite sure what I'm doing wrong as for the file to not execute I realize that owner may be incorrect and hence I may not be able to run the script however

docker exec dockerwordpressmaster_wp-fpm_1 sh chown root:root /var/www/html/wordpress_staging_to_production_image_fixer.sh

sh: can't open 'chown'

Any help in solving this issue will be greatly appreciated

3
  • 1
    sh -c 'chown ...' ? Commented Dec 26, 2017 at 19:16
  • 4
    Try sh /var/www/html/wordpress_staging_to_production_image_fixer.sh Commented Dec 26, 2017 at 19:18
  • docker exec dockerwordpressmaster_wp-fpm_1 sh chown 'root:root /var/www/html/wordpress_staging_to_production_image_fixer.sh' seems to have worked combined with sh /var/www/html/wordpress_staging_to_production_image_fixer.sh seem to be getting the output that im looking for, Thank you all Commented Dec 26, 2017 at 19:20

1 Answer 1

1

The below statement may not have worked for you for two reason

docker exec dockerwordpressmaster_wp-fpm_1 "sh" -c "/var/www/html/wordpress_staging_to_production_image_fixer.sh"

One is Access issues and another is the shebang #!/bin/sh missing at the start of shell script. Your error was "sh: /var/www/html/wordpress_staging_to_production_image_fixer.sh: not found". Which definitely indicates access issue. So you need to chown to root:root or login using the user with id 500.

docker exec sh -c "pwd && chown root:root wordpress_staging_to_production_image_fixer.sh‌​ && sh wordpress_staging_to_production_image_fixer.sh"

Sign up to request clarification or add additional context in comments.

4 Comments

Maybe more explicitly point out the difference between sh /path/to/file and sh -c 'command; command' as well as the difference between absolute and relative paths.
@tripleee what are the differences?
The OP seems not to know the difference between /var and ./var if that's what you mean. They are the same when you are in the root directory, but are you? Running sh -c allows you to pass in an arbitrarily complex sequence of commands, whilst without -c you can only supply the name of an existing script. But conversely, sh -c existingscript requires the existingscript file to be executable, whereas sh existingscript only requires read permissions to the script file.
(And of course, sh chown is just whimsical if you hope to execute /bin/chown which isn't a sh script at all, most places. The OP apparently also needs to better understand the difference between sh and bash.)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.