猿问

Wordpress 插件文件夹默认为 777 权限

环境:


Kubernetes version: v1.16.3  

OS: CentOS 7  

Kernel: Linux k8s02-master01 3.10.0-1062.4.3.el7.x86_64

发生了什么:


我有一个运行从自定义 Apache/Wordpress 图像构建的容器的 Wordpress 部署。我尝试使用 Wordpress 管理员上传插件,但插件文件夹默认为 777 权限。仅插件文件夹,而不是它们的文件。注意到/var/www/html默认情况下设置为 777,然后我尝试chmod 755 /var/www/html在容器上下文中手动...它有效,新插件文件夹默认为 755,但它不是持久的。尝试在 Dockerfile 中进行 chmod,但它不起作用,/var/www/html仍然默认为 777。当我使用官方 Wordpress 图像而不是我的 Dockerfile 时,同样的问题。


是否可以默认/var/www/html为 755 权限?


DOCKERFILE (wordpress-test:5.2.4-apache):


FROM wordpress:5.2.4-apache


RUN sed -i 's/Listen 80/Listen 8080/g' /etc/apache2/ports.conf;

RUN sed -i 's/:80/:8080/g' /etc/apache2/sites-enabled/000-default.conf;

RUN sed -i 's/#ServerName www.example.com/ServerName localhost/g' /etc/apache2/sites-enabled/000-default.conf;


RUN /bin/bash -c 'ls -la /var/www; chmod 755 /var/www/html; ls -la /var/www'


EXPOSE 8080


CMD ["apache2-foreground"]

DockerFILE 构建日志:


Step 8/10 : RUN /bin/bash -c 'ls -la /var/www; chmod 755 /var/www/html; ls -la /var/www';

 ---> Running in 7051d46dd9f3

total 12

drwxr-xr-x 1 root     root     4096 Oct 17 14:22 .

drwxr-xr-x 1 root     root     4096 Oct 17 14:22 ..

drwxrwxrwx 2 www-data www-data 4096 Oct 17 14:28 html

total 12

drwxr-xr-x 1 root     root     4096 Oct 17 14:22 .

drwxr-xr-x 1 root     root     4096 Oct 17 14:22 ..

drwxr-xr-x 2 www-data www-data 4096 Oct 17 14:28 html

在容器上下文中检查结果:


$ kubectl exec -it <POD_NAME> -n development -- sh

(inside the container) $ ls -la /var/www

total 12

drwxr-xr-x. 1 root     root     4096 Oct 17 14:22 .

drwxr-xr-x  1 root     root     4096 Oct 17 14:22 ..

drwxrwxrwx  5 www-data www-data 4096 Dec 17 05:40 html

/var/www/html仍然默认为 777。


繁星淼淼
浏览 182回答 1
1回答

慕桂英3389331

在kubernetes 中,您可以借助initContainers更改已挂载卷的权限。您的部署可能如下所示:apiVersion: apps/v1kind: Deploymentmetadata:&nbsp; name: blog-wordpress&nbsp; namespace: development&nbsp; labels:&nbsp; &nbsp; app: blogspec:&nbsp; selector:&nbsp; &nbsp; matchLabels:&nbsp; &nbsp; &nbsp; app: blog&nbsp; &nbsp; &nbsp; tier: wordpress&nbsp; replicas: 4&nbsp; strategy:&nbsp; &nbsp; type: RollingUpdate&nbsp; &nbsp; rollingUpdate:&nbsp; &nbsp; &nbsp; maxSurge: 2&nbsp; &nbsp; &nbsp; maxUnavailable: 2&nbsp; template:&nbsp; &nbsp; metadata:&nbsp; &nbsp; &nbsp; labels:&nbsp; &nbsp; &nbsp; &nbsp; app: blog&nbsp; &nbsp; &nbsp; &nbsp; tier: wordpress&nbsp; &nbsp; spec:&nbsp; &nbsp; &nbsp; volumes:&nbsp; &nbsp; &nbsp; &nbsp; - name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; persistentVolumeClaim:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; claimName: blog-wordpress&nbsp; &nbsp; &nbsp; initContainers:&nbsp; &nbsp; &nbsp; &nbsp; - name: permission-fix&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image: busybox&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command: ["/bin/chmod","-R","755", "/var/www/html"]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; volumeMounts:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mountPath: /var/www/html/wp-content&nbsp; &nbsp; &nbsp; containers:&nbsp; &nbsp; &nbsp; &nbsp; - name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # image: wordpress:5.2.4-apache&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image: wordpress-test:5.2.4-apache&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; securityContext:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; runAsUser: 33&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; runAsGroup: 33&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allowPrivilegeEscalation: false&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; capabilities:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - "NET_ADMIN"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - "NET_BIND_SERVICE"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - "SYS_TIME"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resources:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; requests:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cpu: "250m"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memory: "64Mi"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; limits:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cpu: "500m"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memory: "128Mi"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ports:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: liveness-port&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; containerPort: 8080&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readinessProbe:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialDelaySeconds: 15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; httpGet:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path: /index.php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; port: 8080&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timeoutSeconds: 15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; periodSeconds: 15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; failureThreshold: 5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; livenessProbe:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialDelaySeconds: 10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; httpGet:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path: /index.php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; port: 8080&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timeoutSeconds: 10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; periodSeconds: 15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; failureThreshold: 5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; env:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Database&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_DB_HOST&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: blog-mysql&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_DB_NAME&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_DB_USER&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-mysql&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: username&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_DB_PASSWORD&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-mysql&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: password&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_TABLE_PREFIX&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: wp_&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_AUTH_KEY&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: auth-key&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_SECURE_AUTH_KEY&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: secure-auth-key&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_LOGGED_IN_KEY&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: logged-in-key&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_NONCE_KEY&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: nonce-key&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_AUTH_SALT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: auth-salt&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_SECURE_AUTH_SALT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: secure-auth-salt&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_LOGGED_IN_SALT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: logged-in-salt&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_NONCE_SALT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueFrom:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKeyRef:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: nonce-salt&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: WORDPRESS_CONFIG_EXTRA&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define('WPLANG', 'fr_FR');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define('WP_CACHE', false);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define('WP_MEMORY_LIMIT', '64M');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; volumeMounts:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - name: blog-wordpress&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mountPath: "/var/www/html/wp-content"编辑: 但是请记住,您只能更改已安装文件夹的权限,而不是父文件夹/文件夹。因此,在上面的示例中,您可以使用:command: ["/bin/chmod","-R","755", "/var/www/html"]但它只会更改/var/www/html/wp-content目录的权限。如果您可以准备好您的卷,使其包含/var/www/html目录并且可以这样安装,您将能够设置其权限。让我知道它是否有帮助。
随时随地看视频慕课网APP
我要回答