簡體   English   中英

無法執行Docker容器的腳本?

[英]Cannot execute script for a docker container?

我不確定為什么,但我似乎無法從主機系統在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:無法打開“小丑”

任何解決此問題的幫助將不勝感激

以下語句可能對您沒有用,原因有兩個

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:未找到”。 這絕對表明訪問問題。 因此,您需要以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”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM