dockerdocker-composedockerfiledocker-networkdocker-engine

Docker Volume Persistence


I am trying to learn Docker. I have installed Docker Desktop on my Windows10 Pro computer.

I started with getting a PHP, MySQL website up and running using Docker.

My docker-compose.yml looks like

version: "3.8"
services:
    www:
        build: .
        ports: 
            - "80:80"
        volumes:
            - ./www:/var/www/html            
        links:
            - db
        networks:
            - default
    db:
        image: mysql:8.0
        ports: 
            - "3306:3306"
        command: --default-authentication-plugin=mysql_native_password
        environment:
            MYSQL_DATABASE: myDb
            MYSQL_USER: user
            MYSQL_PASSWORD: test
            MYSQL_ROOT_PASSWORD: test 
        volumes:
            - ./dump:/docker-entrypoint-initdb.d
            - ./conf:/etc/mysql/conf.d
            - persistent:/var/lib/mysql
        networks:
            - default
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        links: 
            - db:db
        ports:
            - 8000:80
        environment:
            MYSQL_USER: user
            MYSQL_PASSWORD: test
            MYSQL_ROOT_PASSWORD: test 
volumes:
    persistent:

and the DockerFile looks like

FROM php:7.3-apache 
RUN docker-php-ext-install mysqli
RUN apt-get update \
    && apt-get install -y libzip-dev \
    && apt-get install -y wget \
    && apt-get install -y zlib1g-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip

I have a www folder with an index.php.

When I run

docker-compose up -d

I have the PHP, mySQL site up and running correctly and I can access the index.php with expected results.

So far so good.

Now, I want to change the Dockerfile to setup a php forum website (phpbb) - so I have updated my Dockerfile as follows:

FROM php:7.3-apache 
RUN docker-php-ext-install mysqli
RUN apt-get update \
    && apt-get install -y libzip-dev \
    && apt-get install -y wget \
    && apt-get install -y zlib1g-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip

WORKDIR /var/www/html

RUN wget https://download.phpbb.com/pub/release/3.3/3.3.0/phpBB-3.3.0.tar.bz2 \
&& tar -xvjf phpBB-3.3.0.tar.bz2
&& ls -l

When I run

docker-compose build --no-cache

I can see the expected results - i.e, the "ls" command shows all the expected phpBB files in /var/www/html

However, when I run

docker-compose up -d

My container only has the index.php in the /var/www/html (the index.php from the www folder). None of the phpBB files are there.

What am I doing wrong?


Solution

  • The files are there but you are hiding them by your bind mount.

    You are bind mounting ./www into the same directory (/var/www/html) which will hide its contents.

    here:

    www:
      ...
      volumes:
        - ./www:/var/www/html  
    

    When you are building the image, you correctly see the files but once you run docker-compose the bind mount is created and it hides those files.