简体   繁体   English

docker 权限被拒绝 mysql 映像中的 shell 脚本放置在 docker-entrypoint-initdb.d

[英]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.

相关问题 MySql Docker /docker-entrypoint-initdb.d 编码错误 - MySql Docker /docker-entrypoint-initdb.d wrong Encoding 如何等待docker-entrypoint-initdb.d在Shell脚本/ Bash中加载数据库? - How to wait for docker-entrypoint-initdb.d to load DB in Shell Script/Bash? 自定义mysql高山映像未从作为卷安装的docker-entrypoint-initdb.d加载init.sql - Custom mysql alpine image not loading init.sql from docker-entrypoint-initdb.d mounted as a volume 为什么我的 docker-entrypoint-initdb.d 脚本(在 docker-compose.yml 中指定)没有被执行来初始化一个新的 MySQL 实例? - Why isn't my docker-entrypoint-initdb.d script (as specified in docker-compose.yml) executed to initialize a fresh MySQL instance? 无法使用 mysql docker 容器在 docker-entrypoint-initdb.d 中创建数据库 - Can't create db in docker-entrypoint-initdb.d with mysql docker container docker-compose up invalid mode /docker-entrypoint-initdb.d/ - 无法为服务数据库创建容器 - docker-compose up invalid mode /docker-entrypoint-initdb.d/ - cannot create container for service database sql转储是否被加密到docker容器docker-entrypoint-initdb.d中? - Are sql dumps moved into docker container `docker-entrypoint-initdb.d` encrypted? 当容器从另一个容器中启动时,docker-entrypoint-initdb.d 为空 - docker-entrypoint-initdb.d is empty when container is started from within another container 命令&#39;/ bin / sh -c mysql -u wordpress -pwordpress wordpress &lt;/docker-entrypoint-initdb.d/wordpress.sql&#39;返回非零代码:1 - The command '/bin/sh -c mysql -u wordpress -pwordpress wordpress < /docker-entrypoint-initdb.d/wordpress.sql' returned a non-zero code: 1 docker-entrypoint-initdb 中的 MySQL 脚本不执行 - MySQL scripts in docker-entrypoint-initdb are not executed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM