Docker-compose with local Dockerfile not mounting volume properly

Hi There,

I’m trying to figure out why this docker-compose en local Dockerfile are not mounting correctly into ‘./wordpress’. I tried it using image:wordpress and that does work, so that suggest there is something wrong with my Dockerfile, but i canit figure out what.

This is what i use now:

version: '3'
services:
    db:
        image: mysql:5.7
        volumes:
            - db_data:/var/lib/mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: enviu_dev
            MYSQL_DATABASE: enviu_dev    
        networks:
            new:
                aliases:
                    - db
            legacy:
                aliases:
                    - mysql      
    wp:
        build: 
            context: .
            dockerfile: Dockerfile
        volumes:
            - ./wordpress:/var/www/html
        ports:
            - "8080:80"
        networks:
            - legacy
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        networks:
            - new
        ports:
            - 8181:80
        environment:
            PMA_USER: root
            PMA_PASSWORD: enviu_dev     
volumes:
    db_data:

networks:
    new:
    legacy:
# See https://github.com/docker-library/wordpress/tree/618490d4bdff6c5774b84b717979bfe3d6ba8ad1
FROM php:5.6-apache

RUN a2enmod rewrite

COPY /apache/php.ini /usr/local/etc/php/

# install the PHP extensions we need
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev zip && rm -rf /var/lib/apt/lists/* \
	&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
	&& docker-php-ext-install gd
RUN docker-php-ext-install mysqli
RUN apt-get update \
    && apt-get install -y zlib1g-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip 

ENV WORDPRESS_VERSION 4.2.1
ENV WORDPRESS_UPSTREAM_VERSION 4.2.1
ENV WORDPRESS_SHA1 c93a39be9911591b19a94743014be3585df0512f

# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
	&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
	&& tar -xzf wordpress.tar.gz -C /usr/src/ \
	&& rm wordpress.tar.gz \
	&& chown -R www-data:www-data /usr/src/wordpress

I’m using the local Dockerfile to install the zip extension (and probably more later on) and get a

Anyways, any help would be appreciated. It might be a small thing, but i can’t seem to make it working.

The volume mapping in your docker-compose file looks correct. The most likely cause is that your local drive/folder is not shared with the Docker host. What Docker version/OS are you using?

@jdharmon Thanks, i’m using Docker version 17.06.0-ce, build 02c1d87 & OSX Sierra 10.12.5

The weird thing is the volume mapping works for ./db_data and ./wordpress when i use the official wordpress image instead of a local Dockerfile. I’m guessing the Wordpress files aren’t properly installed somehow causing the volume mapping to fail.

I’m trying out some Dockerfile variations (https://github.com/docker-library/wordpress/blob/master/php5.6/apache/Dockerfile for example) and see if that gets it working.

I also tested w/ the official Wordpress image before trying yours, and saw that it was working.

I don’t think your mapping is failing. You can test it by putting a file in your local ./wordpress folder, then run

docker-compose up -d
docker exec -it wp_wp_1 ls /var/www/html

The output of the exec should show the contents of your local directory.

The difference between your Dockerfile and the official one is they have copied in a script and set it as the entrypoint:

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

A quick look at docker-entrypoint.sh looks like it does the setup if it doesn’t find index.php.

Thanks, the local file shows up and when i inspect a snapshot of the installed image (https://stackoverflow.com/a/20816397) i do see all the wordpress files installed properly inside ‘/usr/src/wordpress’ (using https://github.com/docker-library/wordpress/blob/master/php5.6/apache/Dockerfile)

So it seems the wordpress files are installed properly inside the image, but somehow the mapping is not working. I tried moving a level up in the folder hierarchy for the mapping, and that works as expected. Except the actual wordpress files are not showing up… :confused: