Dockerfile “运行 chmod"不生效 [英] Dockerfile "RUN chmod" not taking effect

查看:268
本文介绍了Dockerfile “运行 chmod"不生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其他一切都生效但权限没有改变,我错过了什么吗?

Everything else takes effect but permissions are not changing, am I missing something?

FROM joomla:3.9-php7.2-apache

RUN apt-get update 
&& apt-get install -y apt-utils vim curl

COPY ./joomla_html /var/www/html

RUN chmod -R 765 /var/www/html/

RUN chown -R www-data. /var/www/html/
RUN chmod -R 777 /var/www/html/tmp
RUN chmod -R 777 /tmp
RUN chmod -R 777 /var/www/html/modules
RUN chmod -R 777 /var/www/html/components
RUN chmod -R 777 /var/www/html/administrator/logs
RUN chmod -R 777 /var/www/html/images
RUN chmod -R 777 /var/www/html/uploads

COPY ./docker/php.ini /usr/local/etc/php/conf.d/php-extras.ini

EXPOSE 80

<小时>

这是我得到的,每个文件都有 1000:1000 的权限,我需要它是 www-data


This is what I get, every file has permissions to 1000:1000, I need it to be to www-data

ls -la/var/www/html 的输出是

Output of ls -la /var/www/html is

total 144
drwxr-xr-x 19 1000 1000 4096 May 8 18:53 .
drwxr-xr-x 1 root root 4096 May 8 02:30 ..
drwxr-xr-x 25 1000 1000 4096 May 8 18:53 components
drwxr-xr-x 6 1000 1000 4096 May 8 18:53 images
drwxr-xr-x 68 1000 1000 4096 May 8 18:53 modules
drwxr-xr-x 2 1000 1000 4096 May 8 18:53 tmp
drwxr-xr-x 2 1000 1000 4096 May 8 18:53 uploads

推荐答案

目录定义为上游卷:https://github.com/joomla/docker-joomla/blob/d34ff24288dfb5b27a167f870f1fcca56077be78/ph​​p7.2/apache/Dockerfile#L64

VOLUME /var/www/html

无法使用 RUN 命令修改卷.它们从具有卷的临时容器开始,并且只保存对容器的更改,而不是卷.

Volumes cannot be modified with a RUN command. They start in a temporary container that has the volume, and only the changes to the container, not the volume are saved.

您可以尝试要求上游存储库更改其映像以从 Dockerfile 中删除卷定义.或者,您可以提取他们的存储库并构建您自己的基础映像版本,而无需卷.这些都不会阻止您稍后使用该目录中的卷运行容器.

You can try asking the upstream repo to change their image to remove the volume definition from the Dockerfile. Or you can pull their repo and build your own version of the base image without the volume. Neither of these will prevent you from running the container later with a volume in that directory.

否则,如果您想扩展映像并使用 RUN 命令进行更改,则需要将文件保存在另一个目录中.您还可以有一个入口点,在容器启动时将这些文件复制到/var/www/html.

Otherwise, if you want to extend the image and make changes with RUN commands, you'll need to save your files in another directory. You could also have an entrypoint that copies those files to /var/www/html on container start.

您也可以考虑多阶段构建,在第一阶段修复权限,然后在发布阶段将文件直接复制到卷中.正如您所注意到的,COPY 仍然适用于卷.它不是用临时容器实现的,因此可以将文件直接放在图像文件系统中.

You could also consider a multi stage build, fixing the permissions in the first stage, and then copying the files directly into the volume in the release stage. As you've noticed, COPY still works with volumes. It isn't implement with a temporary container and therefore can place files directly in the image filesystem.

这篇关于Dockerfile “运行 chmod"不生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆