为什么将此卷挂载为只读? [英] Why is this volume mounted as read only?

查看:93
本文介绍了为什么将此卷挂载为只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此链接获得

在进行任何操作之前的初始构建之后,将 uploads.ini 文件夹替换为实际的 uploads.ini 文件..

  file_uploads =开memory_limit = 2000Mupload_max_filesize = 2000Mpost_max_size = 2000Mmax_execution_time = 600 

因此,您的项目(主题)文件夹应如下所示.

现在您可以像这样在此文件夹中开始构建主题,并在此处保留与此本地环境相关联的所有内容.

每次您运行此命令以关闭环境.

  docker-compose down 

下次在此项目上运行此命令.

  docker-compose up -d 

..您以前所有的数据库,插件和上传文件都将完全保留,对于wordpress本地开发人员来说真是太棒了!


一些注意事项.




在此本地wordpress项目中使用GIT

如果您使用GIT将项目保存为存储库,请确保您的 .gitignore 文件不包括这些文件/文件夹.

 /供应商/上传/D b/dist/node_modules/插件 

值得为您的/db /plugins /uploads 文件夹设置备用的云备份解决方案,例如Google驱动器,以防万一硬盘故障之类的东西.




部署到服务器,登台生产

在此项目的IDE设置中,您可能希望将某些文件和文件夹排除在部署到 staging production 服务器环境之外,这是我通常所排除的.

 /Users/joshmoto/Sites/demo/db/用户/joshmoto/站点/演示/node_modules/用户/joshmoto/站点/演示/src/用户/joshmoto/站点/演示/上传/Users/joshmoto/Sites/demo/composer.json/用户/joshmoto/站点/demo/composer.lock/Users/joshmoto/Sites/demo/docker-compose.yml/Users/joshmoto/Sites/demo/package-lock.json/Users/joshmoto/Sites/demo/package.json/Users/joshmoto/Sites/demo/uploads.ini/Users/joshmoto/Sites/demo/webpack.mix.js/用户/joshmoto/站点/演示/插件/Users/joshmoto/Sites/demo/.gitignore/用户/joshmoto/站点/演示/供应商 

  • /plugins 我通过通过cPanel或wordpress仪表板上传进行手动管理,因为在同步到远程时索引非常繁琐.
  • /vendors 是由作曲家生成的,并且存在相同的问题,索引很疯狂,因此最好手动将其压缩并通过cPanel或您使用的任何服务器管理员上载.



如果您在通过wordpress仪表板在本地上传媒体和插件时遇到问题

有时,dockers wordpress容器的 wp-content 文件夹可能会遇到一些权限问题.这很容易解决.当您的项目在docker中启动并运行时,在项目中运行以下docker compose命令以更改 wp-content 文件夹上的权限.

显示正在运行的docker容器命令.

  docker ps 

返回结果.

 容器ID图像命令创建的状态端口名称4052536e574a wordpress:最新的"docker-entrypoint.s…"1小时之前1小时0.0.0.0:80->80/tcp demo_wordpress_1b0fbb0a8f9e6 mysql:5.7"docker-entrypoint.s…"1小时前上1小时0.0.0.0:3306->3306/tcp,33060/tcp demo_db_1769262e584e7 mailhog/mailhog:latest"MailHog"1小时前上1小时1025/tcp,0.0.0.0:8025->8025/tcp demo_mailhog_1 

复制并记下 wordpress:latest 容器ID,在此示例中,我的容器ID为..

 <代码> 4052536e574a 

现在使用此wordpress容器ID运行此命令以执行此容器目录中的内容.

  docker exec -it 4052536e574a/bin/bash 

返回结果.

  root @ 4052536e574a:/var/www/html# 

现在我们位于容器的根目录中,您现在可以运行此命令,该命令将在 wp-content 上递归更改权限,并修复本地wordpress仪表板中的上载权限问题.

  chown -R www-data:www-data wp-content 

您可能必须在项目文件夹上运行 docker-compose down docker-compose up -d 命令,这些更改才能生效,但我认为您也需要.




如果要使用本地自定义URL而不是http://localhost

在终端(这次不在您的项目文件夹中)中,运行此命令来编辑主机文件.

  sudo nano/etc/hosts 

然后,在通过 Exit ..

之前,通过终端和 WriteOut 将自定义网址添加到主机文件中.

  127.0.0.1 local.demo.com 

现在您的重定向掩码已保存在主机中,您需要将其添加到/*下面的 docker-compose.yml 中,其他wp-config在此处定义*/..

  define('WP_HOME','http://local.demo.com');define('WP_SITEURL','http://local.demo.com'); 

不幸的是,您不能使用 https ,而必须使用 http .

您需要 docker-compose down docker-compose up -d ,这些新定义的配置才能在本地 wp-config.php中运行.




处理您的暂存和生产wp-config

您的服务器环境应使用独特的盐等独立安装,您不应 docker-compose.yml 配置中获取任何东西,实际上您只想添加这些内容最初是多余的定义.

登台 wp-config.php

  define('ENVIRONMENT','staging');define('WP_DEBUG',true);define('WP_HOME','https://staging.demo.com');define('WP_SITEURL','https://staging.demo.com'); 

生产 wp-config.php

  define('ENVIRONMENT','production');define('WP_DEBUG',false);define('WP_HOME','https://www.demo.com');define('WP_SITEURL','https://www.demo.com'); 




更新dockers wordpress图片

您无法通过wordpress仪表板更新本地wordpress网站.在我的 docker-compose.yml 示例中,我定义了 image:wordpress:latest ,该图像将获取安装在docker应用中的最新wordpress图像.

这意味着,如果您在当时使用旧版wordpress的项目中 docker-compose up -d ,则该项目将更新为docker上安装的最新wordpress映像.

>

我还没有在 docker-compose.yml 中亲自定义wordpress图像版本,但是如果您不希望某些项目在下次 docker-compose时使用最新图像,则可以-d 一个项目.

您必须使用此命令手动更新wordpress docker映像.

  docker pull wordpress 

并且您将不得不 docker-compose down docker-compose up -d ,项目才能使用最新更新,有时需要对wordpress数据库进行更新通过浏览器首次访问该网站时.




通过仪表板上传/删除插件时的权限问题

要更改 wp-content 文件夹上的权限,以便可以通过仪表板编写 uploads plugins .

确保在容器运行时在下面运行这些命令...

  1. 显示容器命令...
    docker ps
  2. 记下正在运行的 wordpress 图片
  3. 的容器ID
  4. 在容器中执行命令(用没有括号的ID替换 [container_id] )...
    docker exec -it [container_id]/bin/bash
  5. 更改wp-content文件夹的权限...
    chown -R www-data:www-data wp-content

这应该可以解决通过docker compose在本地通过 uploads plugins 的仪表板上载和删除文件的任何问题.

I got from this link https://hub.docker.com/_/wordpress a docker-compose.yml file like this.

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

But the volume is not getting mounted on the wordpress folder, and if I delete "wordpress" to mount the volume on the local folder it gets mounted but it does as read only. I don't have a Dockerfile am I just using the default image and that's the problem?

解决方案

I use docker all the time for wordpress, this is my workflow.. (on a Mac)

Create a project folder and add a docker-compose.yml file with this..

version: '3.7'

services:

  # here is our mysql container
  db:
    image: mysql:5.7
    volumes:
      - ./db:/var/lib/mysql:delegated
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  # here is our wordpress container
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      # our persistent local data re routing
      - .:/var/www/html/wp-content/themes/testing:delegated
      - ./plugins:/var/www/html/wp-content/plugins
      - ./uploads:/var/www/html/wp-content/uploads
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    ports:
      - "80:80"
    restart: always
    environment:
      # our local dev environment
      WORDPRESS_DEBUG: 1
      DEVELOPMENT: 1
      # docker wp config settings
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_AUTH_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_SECURE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_LOGGED_IN_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_NONCE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_SECURE_AUTH_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_LOGGED_IN_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_NONCE_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_CONFIG_EXTRA: |

        /* Development parameters */
        define('WP_CACHE', false);
        define('ENVIRONMENT', 'local');

        /* Configure mailhog server */
        define('WORDPRESS_SMTP_AUTH', false);
        define('WORDPRESS_SMTP_SECURE', '');
        define('WORDPRESS_SMTP_HOST', 'mailhog');
        define('WORDPRESS_SMTP_PORT', '1025');
        define('WORDPRESS_SMTP_USERNAME', null);
        define('WORDPRESS_SMTP_PASSWORD', null);
        define('WORDPRESS_SMTP_FROM', 'whoever@example.com');
        define('WORDPRESS_SMTP_FROM_NAME', 'Whoever');

        /* other wp-config defines here */

  # here is our mailhog container
  mailhog:
    image: mailhog/mailhog:latest
    ports:
      - "8025:8025"

Then in this project folder run this terminal command (with docker app running)..

docker-compose up -d

..and bam you will have a wordpress site at http://localhost/

This docker-compose.yml is configured so you will have..

  • Wordpress site at http://localhost/ or http://localhost:80
  • Mailhog server that captures all outgoing mail at http://localhost:8025/
  • Persistent local database, plugins, uploads and uploads.ini

All persistent data is mapped to this project folder, which is your theme folder. This keeps things nice and collected for each project..

After initial build before you do anything, replace the uploads.ini folder with an actual uploads.ini file..

file_uploads = On
memory_limit = 2000M
upload_max_filesize = 2000M
post_max_size = 2000M
max_execution_time = 600

So your project (theme) folder should look like this..

Now you can start building your theme in this folder like this, keeping everything associated with this local environment here.

Every time you run this command to shut down the environment..

docker-compose down

Next time you run this command on this project..

docker-compose up -d

..all your previous database, plugins and uploads will be exactly where you left off, awesome for wordpress local dev!


A few considerations to take into account..




Using GIT with this local wordpress project

If your using GIT to save this project as a repository, then make sure your .gitignore file excludes these files/folders..

/vendor
/uploads
/db
/dist
/node_modules
/plugins

Worth having an alternate cloud backup solution setup like google drive for your /db, /plugins and /uploads folders, just in case of hard drive failure or something.




Deploying to server, staging and production

In your IDE settings for this project you may want exclude certain files and folder from being deployed to staging and production server environments, this is what I normally exclude..

/Users/joshmoto/Sites/demo/db
/Users/joshmoto/Sites/demo/node_modules
/Users/joshmoto/Sites/demo/src
/Users/joshmoto/Sites/demo/uploads
/Users/joshmoto/Sites/demo/composer.json
/Users/joshmoto/Sites/demo/composer.lock
/Users/joshmoto/Sites/demo/docker-compose.yml
/Users/joshmoto/Sites/demo/package-lock.json
/Users/joshmoto/Sites/demo/package.json
/Users/joshmoto/Sites/demo/uploads.ini
/Users/joshmoto/Sites/demo/webpack.mix.js
/Users/joshmoto/Sites/demo/plugins
/Users/joshmoto/Sites/demo/.gitignore
/Users/joshmoto/Sites/demo/vendor

  • /plugins I manually manage by uploading through cPanel or wordpress dashboard, because the indexing is so heavy when syncing to remote.
  • /vendors is generate from composer and the same problem, the indexing is crazy so best to manually zip this up and upload through cPanel or whatever server admin you use.



If you have problems uploading media and plugins locally via the wordpress dashboard

You may be faced with some permission problems sometimes with dockers wordpress container wp-content folder. It is an easy fix. While your project is up and running in docker, in the project run these docker compose commands to change permissions on wp-content folder..

Show running docker containers command..

docker ps

Returned result..

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                               NAMES
4052536e574a        wordpress:latest         "docker-entrypoint.s…"   1 hour ago          Up 1 hour           0.0.0.0:80->80/tcp                  demo_wordpress_1
b0fbb0a8f9e6        mysql:5.7                "docker-entrypoint.s…"   1 hour ago          Up 1 hour           0.0.0.0:3306->3306/tcp, 33060/tcp   demo_db_1
769262e584e7        mailhog/mailhog:latest   "MailHog"                1 hour ago          Up 1 hour           1025/tcp, 0.0.0.0:8025->8025/tcp    demo_mailhog_1

Copy and take note the wordpress:latest container ID, in this example my container ID is..

4052536e574a

Now run this command using this wordpress container ID to execute stuff in this container directory..

docker exec -it 4052536e574a /bin/bash

Returned result..

root@4052536e574a:/var/www/html#

Now we are in the containers root directory you can now run this command which will change the permissions recursively on the wp-content and fix the uploading permissions issue in the local wordpress dashboard.

chown -R www-data:www-data wp-content

You may have to run docker-compose down and docker-compose up -d commands on the project folder for these changes to take effect but I don't think you need too.




If you want a local custom URL instead of http://localhost

In terminal (not in your project folder this time) run this command to edit your hosts file..

sudo nano /etc/hosts

Then add your custom url to your hosts file via terminal and WriteOut before you Exit..

127.0.0.1  local.demo.com

Now your redirect mask is saved in your hosts you will need to add this to your docker-compose.yml below /* other wp-config defines here */..

define('WP_HOME','http://local.demo.com');
define('WP_SITEURL','http://local.demo.com');

Unfortunately you can't use https, you have to use http.

You will need to docker-compose down and docker-compose up -d for these newly define configs to run in your local wp-config.php.




Handling your Staging and Production wp-config

Your server environments should be independently installed with unique salts etc, you should not take anything from the docker-compose.yml config, really you only want to add these extra defines initially..

Staging wp-config.php

define('ENVIRONMENT', 'staging');
define('WP_DEBUG', true);
define('WP_HOME','https://staging.demo.com');
define('WP_SITEURL','https://staging.demo.com');

Production wp-config.php

define('ENVIRONMENT', 'production');
define('WP_DEBUG', false);
define('WP_HOME','https://www.demo.com');
define('WP_SITEURL','https://www.demo.com');




Updating dockers wordpress image

You can't update your local wordpress site via the wordpress dashboard. In my docker-compose.yml example I am defining image: wordpress:latest which gets the latest wordpress image installed on your docker app.

This means if you docker-compose up -d on a project that was using an older version of wordpress at the time, this project would update to the latest wordpress image installed on docker.

I've not personally defined wordpress image versions in docker-compose.yml but you can if you do not want certain projects to use the latest image when you next docker-compose up -d a project.

You have to update the wordpress docker image manually using this command..

docker pull wordpress

And you will have to docker-compose down and docker-compose up -d for your project to use the latest update, which some times requires a wordpress database update when accessing the site for the first time through your browser.




Permission issues when uploading / deleting plugins via dashboard

To change the permissions on the wp-content folder so uploads and plugins can be written via the dashboard.

Make sure you run these commands below while the containers are running...

  1. Show containers command...
    docker ps
  2. Make a note of the container ID for the running wordpress image
  3. Execute in container command (replace [container_id] with your ID with no brackets)...
    docker exec -it [container_id] /bin/bash
  4. Change permissions on wp-content folder...
    chown -R www-data:www-data wp-content

This should resolve any problems uploading and deleting files via the dashboard for uploads and plugins locally with docker compose.

这篇关于为什么将此卷挂载为只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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