简体   繁体   中英

Problems sharing Docker Wordpress volume with the host

I am trying to make a plugin for Wordpress. Never did this before, but I found a decent tutorial. I only need to hook-up my existing working React SPA to Wordpress for correct bootstrapping. In order to ease the setup, somewhat, I want to run Wordpress on Docker sharing the persistent directory where my code will live. In order to do this, I made the below docker compose configuration.

version: "3.3"
services:
  db:
    image: mysql:8.0.23
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - wordpress:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {}
  wordpress: {}

When I inspect the container, it shows that there is a mount point as below:

$ docker inspect -f "{{ .Mounts }}" f65b5f96c785
[{volume wp-plugin_wordpress /var/lib/docker/volumes/wp-plugin_wordpress/_data /var/www/html local rw true }]

There is no such a directory on the local disk, anywhere. Further, I could do ls as:

$ docker exec f65b5f96c785 ls -l
total 224
-rw-r--r--  1 www-data www-data   405 Feb  6  2020 index.php
-rw-r--r--  1 www-data www-data 19915 Feb 12  2020 license.txt
-rw-r--r--  1 www-data www-data  7278 Jun 26  2020 readme.html
-rw-r--r--  1 www-data www-data  7101 Jul 28  2020 wp-activate.php
drwxr-xr-x  9 www-data www-data  4096 Feb  3 21:11 wp-admin
-rw-r--r--  1 www-data www-data   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 www-data www-data  2328 Oct  8 21:15 wp-comments-post.php
-rw-r--r--  1 www-data www-data  2823 Feb  7 17:33 wp-config-sample.php
-rw-r--r--  1 www-data www-data  3199 Feb  7 17:33 wp-config.php
drwxrwxrwx  5 www-data www-data  4096 Feb  7 17:33 wp-content
-rw-r--r--  1 www-data www-data  3939 Jul 30  2020 wp-cron.php
drwxr-xr-x 25 www-data www-data 16384 Feb  3 21:11 wp-includes
-rw-r--r--  1 www-data www-data  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--  1 www-data www-data  3300 Feb  6  2020 wp-load.php
-rw-r--r--  1 www-data www-data 49831 Nov  9 10:53 wp-login.php
-rw-r--r--  1 www-data www-data  8509 Apr 14  2020 wp-mail.php
-rw-r--r--  1 www-data www-data 20975 Nov 12 14:43 wp-settings.php
-rw-r--r--  1 www-data www-data 31337 Sep 30 21:54 wp-signup.php
-rw-r--r--  1 www-data www-data  4747 Oct  8 21:15 wp-trackback.php
-rw-r--r--  1 www-data www-data  3236 Jun  8  2020 xmlrpc.php

Yet, when I search for these files locally, as below nothing is found:

find / -name wp-activate.php 2>/dev/null

Hence, something is obviously wrong. What am I doing wrong and what should I do, to have my volume mapped to a local path?

Try this flow:

mkdir -P /srv/wordpress/
cd /srv/wordpress/
mkdir plugins themes uploads
nano docker-compose.yaml

and put in docker-compose.yaml this code:

version: '3.6'

services:
  db:
    image: mysql:8.0.23
    volumes:
      - data_db:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: mypassword
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    image: wordpress:latest
    depends_on:
      - db
    ports:
      - 8080:80
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    volumes:
      - .wordpress/plugins:/var/www/html/wp-content/plugins
      - .wordpress/themes:/var/www/html/wp-content/themes
      - .wordpress/uploads:/var/www/html/wp-content/uploads
  volumes:
    data_db:

and run:

docker-compose up -d

https://gridscale.io/en/community/tutorials/dockerize-wordpress-with-docker-compose/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM