dockerdocker-composewindows-10dockerfiledocker-toolbox

Docker toolbox volume mounting not working on windows 10


I am new to docker

Here is my configuration

Folder Structure

Test :
     - docker-compose.yml
     - Dockerfile
     - www
         - index.html

Docker YML

version: "3"
services:
    www:
        build: .
        ports:
            - "8001:80"
        volumes:
            - ./www:/var/www/html/
        links:
            - db
        networks:
            - default
    db:
        image: mysql:8.0.16
        command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
        ports:
            - "3306:3306"
        environment:
            MYSQL_DATABASE: myDb
            MYSQL_USER: user
            MYSQL_PASSWORD: test
            MYSQL_ROOT_PASSWORD: test
        volumes:
            - ./dump:/docker-entrypoint-initdb.d
            - persistent:/var/lib/mysql
        networks:
            - default
    phpmyadmin:
        image: phpmyadmin/phpmyadmin:4.8
        links:
            - db:db
        ports:
            - 8000:80
        environment:
            MYSQL_USER: user
            MYSQL_PASSWORD: test
            MYSQL_ROOT_PASSWORD: test
volumes:
    persistent:

Dockerfile

FROM php:7.2.6-apache
RUN docker-php-ext-install mysqli pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN chmod -R 775 /var/www/html

phpmyadmin dashboard working correctly, But when i enter the web url it shows 403 forbidden error

When it check the log it shows an error like this :

[Mon Sep 02 12:00:44.290707 2019] [autoindex:error] [pid 18] [client 192.168.99.1:52312] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
192.168.99.1 - - [02/Sep/2019:12:00:44 +0000] "GET / HTTP/1.1" 403 508 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"

and my "/var/www/html" directory was empty. How can i fix it ?

Update

I created a file index.php using bash it worked, but i can't locate index.php file on my file system Bash command and browser screenshot

Please help

If you need any additional info feel free to ask :).

Thanks


Solution

  • Finally i figured the issue, i am using docker toolbox so it only mount C:\Users directory but my project folder is on d drive. so i have to mount my D:\projects directory to vm shared folder. i followed the below steps

    1. In Virtual Box under 'Settings' -> 'Shared Folders' added 'projects' and pointed it to the location I want to mount. In my case this is 'D:\projects' (Auto-mount and Make Permanent enabled)
    2. Start Docker Quickstart Terminal
    3. Type 'docker-machine ssh default' (the VirtualBox VM that Docker uses is called 'default')
    4. Go to the root of the VM filesystem, command 'cd /'
    5. Switch to the user root by typing 'sudo su'
    6. Create the directory you want to use as a mount point. Which in my case is the same as the name of the shared folder in VirtualBox: 'mkdir projects'
    7. Mount the VirtualBox shared folder by typing 'mount -t vboxsf -o uid=1000,gid=50 projects /projects' (the first 'projects' is the VirtualBox shared folder name, the second '/projects' is the directory I just created and want to use as the mount point).
    8. Now I can add a volume to my Docker file like this: '- /projects/test/www/build/:/var/www/html/' (left side is the /projects mount in my VM, the right side is the directory to mount in my docker container)
    9. Run the command 'docker-compose up' to start using the mount (to be clear: run this command via the Docker Quickstart Terminal outside of your SSH session on your local file system where your docker-compose.yml file is located).

    And i change the docker-compose.yml like this :

    version: "3"
    services:
        www:
            build: 
             context: .
             dockerfile: Dockerfile
            ports:
                - "8001:80"
            volumes:
                - /projects/test/www:/var/www/html/
            links:
                - db
            networks:
                - default
        db:
            image: mysql:8.0.16
            command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
            ports:
                - "3306:3306"
            environment:
                MYSQL_DATABASE: myDb
                MYSQL_USER: user
                MYSQL_PASSWORD: test
                MYSQL_ROOT_PASSWORD: test
            volumes:
                - ./dump:/docker-entrypoint-initdb.d
                - persistent:/var/lib/mysql
            networks:
                - default
        phpmyadmin:
            image: phpmyadmin/phpmyadmin:4.8
            links:
                - db:db
            ports:
                - 8000:80
            environment:
                MYSQL_USER: user
                MYSQL_PASSWORD: test
                MYSQL_ROOT_PASSWORD: test
    volumes:
        persistent:
    

    i also updated the oracle vm. I found this solution from here : https://github.com/moby/moby/issues/22430#issuecomment-215974613 Thanks bro :)