[英]docker permission denied for shell script in mysql image placed at docker-entrypoint-initdb.d
FROM mysql:latest
RUN set -ex && apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y --no-install-recommends \
curl unzip
ADD my.sh /docker-entrypoint-initdb.d
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/
RUN chmod -R 777 docker-entrypoint-initdb.d
Content of my.sh file are: my.sh 文件的内容是:
#!/bin/bash
mkdir try1
The my.sh file has a command to create a directory and when the entrypoint.sh of the image runs this file, it throws a permission denied error. my.sh 文件有一个创建目录的命令,当镜像的 entrypoint.sh 运行这个文件时,它会抛出一个权限被拒绝的错误。 I have changed the owner of the directory as well.
我也更改了目录的所有者。 What could be the reason.
可能是什么原因。
Script in docker-entrypoint-initdb.d
will be executed by mysql
account, not by root
, see source code . docker-entrypoint-initdb.d
中的脚本将由mysql
帐户执行,而不是由root
执行,请参阅源代码。
You could verify it by change my.sh
as next:您可以通过将
my.sh
更改为下一个来验证它:
#!/bin/bash
echo "start"
pwd
id
mkdir try1
echo "done"
Then, the error log will be:然后,错误日志将是:
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/my.sh
start
/
uid=999(mysql) gid=999(mysql) groups=999(mysql)
mkdir: cannot create directory 'try1': Permission denied
You could see the user which run current my.sh
is mysql
, while you currently want to setup try1
folder in /
, surely you won't have permission.您可以看到运行当前
my.sh
的用户是mysql
,而您当前想在/
中设置try1
文件夹,您肯定没有权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.