Docker Compose WordPress Volumes Appear Empty

2020-04-11 01:24发布

问题:

I'm trying to set up a simple WordPress build using docker compose. However, when I build it, the volumes appear to be empty.

Here is my docker-compose.yml:

version: '3'
services:
    wordpress:
        image: wordpress
        restart: always
        ports:
            - 8000:80
        volumes:
            - ./development:/var/www/html
        environment:
            WORDPRESS_DB_HOST: db
            WORDPRESS_DB_NAME: wordpress
            WORDPRESS_DB_USER: root
            WORDPRESS_DB_PASSWORD: password
        depends_on:
            - db
        networks:
            - wordpress-network
    phpmyadmin:
        image: phpmyadmin/phpmyadmin:latest
        ports:
            - 8080:80
        links:
            - db:db
    db:
        image: mariadb:latest
        ports:
            - 127.0.0.1:3306:3306
        command: [
            '--default_authentication_plugin=mysql_native_password',
            '--character-set-server=utf8mb4',
            '--collation-server=utf8mb4_unicode_ci'
        ]
        volumes:
            - wp-data:/var/lib/mysql
        environment:
            MYSQL_DATABASE: wordpress
            MYSQL_ROOT_PASSWORD: password
        networks:
            - wordpress-network
networks:
    wordpress-network:
        driver: bridge

volumes:
    wp-data:
        driver: local

Here is my local project structure, with theme stylesheet:

I run docker-compose to build the image: docker-compose up -d --build

But when I open the build in my browser, it looks like the theme is empty:

This leads me to believe the volume is empty. I'd appreciate any help or insights into this issue, thank you.

回答1:

In your docker-compose file you say ./wp-data:/var/lib/mysql which is host folder mapping (not volume) but in your docker-compose you define docker named volume called wp-data and if you want to use this volume you have to use it as wp-data:/var/lib/mysql. I would also suggest to remove ${PWD} because it might cause problem in sh