无法执行docker容器的脚本?

问题描述 投票:0回答:1

我不知道为什么,但我似乎无法在主机系统的docker容器内运行此脚本

在主机上我在shell脚本中执行此代码

#!/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

这个脚本大部分工作正常,我甚至可以在正确的目录中看到这个文件

/var/www/html/

我可以清楚地看到该文件存在于容器内部

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

但是,当我尝试从容器内执行脚本时

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

sh:无法打开'./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:未找到

docker exec dockerwordpressmaster_wp-fpm_1 sh -c wordpress_staging_to_production_image_fixer.sh

sh:wordpress_staging_to_production_image_fixer.sh:找不到

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:没有这样的文件或目录

我不太确定我做错了,因为文件没有执行我意识到所有者可能是不正确的因此我可能无法运行脚本然而

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

sh:无法打开'chown'

任何帮助解决这个问题将不胜感激

linux bash shell docker
1个回答
1
投票

由于两个原因,以下声明可能对您不起作用

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

一个是Access问题,另一个是在shell脚本开头缺少的shebang #!/bin/sh。您的错误是“sh:/var/www/html/wordpress_staging_to_production_image_fixer.sh:not found”。这肯定表明访问问题。所以你需要chown到root:root或使用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”

© www.soinside.com 2019 - 2024. All rights reserved.