wordpress icon indicating copy to clipboard operation
wordpress copied to clipboard

Problem with adding volume /var/www/html

Open m-pawelczyk opened this issue 10 years ago • 7 comments

I have tried to run command: docker run -e WORDPRESS_DB_PASSWORD=password -d --name wordpress --link wordpressdb:mysql -p 127.0.0.1:38080:80 -v /home/mp/docker/wordpress:/var/www/html wordpress

and my docker image exit unsuccessfully with logs:

tar: ./wp-includes: Cannot mkdir: Permission denied tar: ./wp-includes/script-loader.php: Cannot open: No such file or directory tar: ./wp-includes: Cannot mkdir: Permission denied tar: ./wp-includes/session.php: Cannot open: No such file or directory tar: ./wp-includes: Cannot mkdir: Permission denied tar: ./wp-includes/shortcodes.php: Cannot open: No such file or directory

Sorry if I write this question in wrong place, but I cannot find answer in web. I put full rights to /home/mp/docker/wordpress but it also not helped:

[mp@kruk wordpress]$ ls -la /home/mp/docker/wordpress/ total 8 drwxrwxrwx. 2 mp mp 4096 Mar 15 22:33 .

Command: docker run -e WORDPRESS_DB_PASSWORD=password -d --name wordpress --link wordpressdb:mysql -p 127.0.0.1:38080:80 -v /home/mp/docker/wordpress:/var/www/html wordpress works fine, but I need access to volume to change templates during developing them.

Thank you for help.

m-pawelczyk avatar Mar 15 '16 21:03 m-pawelczyk

If you do sudo chown 33:33 /home/mp/docker/wordpress before trying to start the container, does that work?

tianon avatar Mar 15 '16 23:03 tianon

I have tried this modification, but my problem still exists.

[mp@kruk ~]$ ls -la /home/mp/docker/ total 20 drwxrwxr-x. 3 mp mp 4096 Mar 17 21:40 . drwx------. 22 mp mp 4096 Mar 17 21:34 .. drwxrwxr-x. 2 33 33 4096 Mar 17 21:40 wp [mp@kruk ~]$ [mp@kruk ~]$ docker run -e WORDPRESS_DB_PASSWORD=password -d --name wordpress --link wordpressdb:mysql -p 127.0.0.1:8080:80 -v /home/mp/docker/wp:/var/www/html wordpress 6e6e03c124c9470ad1e4acb949c0df53115a38000721f960c300d29fbfd1a133 Usage of loopback devices is strongly discouraged for production use. Either use --storage-opt dm.thinpooldev or use --storage-opt dm.no_warn_on_loop_devices=true to suppress this warning. [mp@kruk ~]$ [mp@kruk ~]$ docker logs wordpress WordPress not found in /var/www/html - copying now... ls: cannot open directory .: Permission denied tar: ./index.php: Cannot open: Permission denied tar: ./license.txt: Cannot open: Permission denied tar: ./readme.html: Cannot open: Permission denied tar: ./wp-activate.php: Cannot open: Permission denied

I have thought that on my OS (Fedora 23) the problem is groupID 33 which was used by tape. I have changed that groupID, but it still not work.

I have checked it in Centos 7 and it works OK.

Do you have another ideas what could be wrong?

m-pawelczyk avatar Mar 17 '16 20:03 m-pawelczyk

Hi I have a related question, I'm trying to mount the upload folder to a persistent data volume but I got always permission denied:

This is the docker-compose that I'm using:

version: '2'
services:
  web:
    container_name: web
    image: wordpress
    volumes:
      - data-web:/var/www/html/wp-content/uploads:rw
    depends_on:
      - db
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_PASSWORD=mypass
    ports:
      - 7999:80
  db:
    image: mysql
    container_name: db
    environment:
      - MYSQL_ROOT_PASSWORD=mypass
    volumes:
      - data-db:/var/log/mysql
volumes:
  data-db: {}
  data-web: {}

And after wordpress is started I try to upload a file through the web admin console but I got:

Unable to create directory wp-content/uploads/2016/03. Is its parent directory writable by the server?

I checked the /var/www/html/wp-content/uploads and the owner is different than plugins and themes folder:

-rw-r--r-- 1 www-data www-data   28 Jan  8  2012 index.php
drwxr-xr-x 3 www-data www-data 4096 Feb  2 17:12 plugins
drwxr-xr-x 5 www-data www-data 4096 Feb  2 17:12 themes
drwxr-xr-x 2 root     root     4096 Mar 22 08:21 uploads

Is there a better way to do this? I know that I can mount this folder with a shared host folder and do a chmod 777 and will work but I would prefer to use data volumes as docker recommends.

Thanks. Gerard.

GerardRibas avatar Mar 22 '16 08:03 GerardRibas

Hi, my problem is resolved. The problem is that setenforce 0 works differently on Fedora and CentOS. I don't know why.

[mp@localhost ~]$ getenforce
Enforcing
[mp@localhost ~]$ sudo setenforce 0
[mp@localhost ~]$ getenforce
Permissive
[mp@localhost ~]$ cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

Line SELINUX=enforcing cause that after reboot getenforce will return Enforcing. It works differently on CentOS and Fedora.

m-pawelczyk avatar Mar 25 '16 06:03 m-pawelczyk

Gerard, Check SELinux permissions as I wrote above.

m-pawelczyk avatar Mar 25 '16 06:03 m-pawelczyk

Closing since this is an SELinux issue, not something we can fix in the image.

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

tianon avatar Jan 09 '18 23:01 tianon

Instead of disabling selinux enforcement, add z or Z to the volume mount options. For example, in docker-compose.yml, do:

    volumes:
      - data-web:/var/www/html/wp-content/uploads:rwz

See https://prefetch.net/blog/2017/09/30/using-docker-volumes-on-selinux-enabled-servers/ for a nice explanation.

candrews avatar Mar 05 '19 21:03 candrews