Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Not working on Windows #171

Closed
devcustrom opened this issue Aug 26, 2021 · 10 comments
Closed

[BUG] Not working on Windows #171

devcustrom opened this issue Aug 26, 2021 · 10 comments
Assignees

Comments

@devcustrom
Copy link
Contributor

Describe the bug
Just run on windows

which Branch / PHP Version are you using ?
php8

To Reproduce
Steps to reproduce the behavior:

  1. git clone https://github.com/sprintcube/docker-compose-lamp.git
  2. cd docker-compose-lamp/
  3. cp sample.env .env
  4. docker-compose up -d
  5. Visit localhost and see
    image
@devcustrom devcustrom changed the title [BUG] [BUG] Not working on Windows Aug 26, 2021
@MrOffline77
Copy link
Collaborator

MrOffline77 commented Sep 3, 2021

Hi I can not currently understand the problem since I currently have no Windows available. Are you using WSL or directly docker on the Windows ?
I just built fresh against the master and everything works for me on the mac.

@ralphskie
Copy link

just installed on docker for windows, and encountered this error.

Why, default .env mysql port is 3306, This is not available on my machine, so I change it to something 3310.
Issue docker-compose up -d

All services with "lamp-databse" should start succesfully. After that go to www/test_db_pdo.php and change 3306 on line 8 to 3310 or the port you use.

change
$database = 'mysql:host=database:3306';

to
$database = 'mysql:host=database:3310';

@markus-michalski
Copy link

I had the same but I tested the connection via pdo and mysqli with the provided links on the right side. Since this worked, I ignored the error on the left side.
Is this something I have to fix?

@MrOffline77
Copy link
Collaborator

Thanks for the reports everyone.

Ok lets summarize

Index.php
$link = mysqli_connect("database", "root", $_ENV['MYSQL_ROOT_PASSWORD'], null);

Link on the right side:
$link = mysqli_connect("database", "root", $_ENV['MYSQL_ROOT_PASSWORD'], null);

Ok this looks the same. We could add a mysql port option to the env file and reference this env variable im the index.php and the two conn test links on the right side as port variable.
In addition we should mention this issue in the readme and directly inside the env file. So that windows user are aware of the fact they need to use the non default mysql port on windows10 to get this going.

This should work as workarround I guess. Can someone confirm this ?
Other approaches to solve this are welcome.

The reason why windows is not allowing port 3306 inside the docker bridge is a mystery to me… maybe some antivirus stuff on the machine ?

@cljk
Copy link

cljk commented Sep 14, 2021

I´m running it in WSL 2 on Win 10 - which works perfectly so far.

I believe what you are seeing could also be a compatiblity problem of mysql in docker container with hosted volumes on Windows as I recognize a comparable problem in the past. As I remember using host mounted volumes on docker for windows mysql starts up one time and then fails to start because of access right problems.

You could try using a docker volume instead

@MrOffline77
Copy link
Collaborator

I now have a Windows System available with debian wsl2 and docker desktop wsl2.
When using the mounted Windows Filesystems paths there is a problem with starting the mysql Container due to permissions issues.
When using the WSL2 own Filesystem of the Linux Subsystem Container instead of the mounts, the issue does not occur.
So basically you just need to git clone the project inside your WSL2 Linux Users Home Directory instead of using the Windows mounts to your c Disk.

@cljk
Copy link

cljk commented Jan 16, 2022

If you are interested ... I have my mysql docker container with a modified configuration to be able to use host mounted volumes on Windows WSL.

Just add a volume mapping for a configuration file to your docker-compose,yml:

       - ./docker/innodb-fix.cnf:/etc/mysql/conf.d/innodb-fix.cnf

And place the file docker/innodb-fix.cnf in your project with

[mysqld]
innodb_flush_method=littlesync
innodb_use_native_aio=OFF

# log_bin=ON
skip-log-bin
disable_log_bin
binlog_expire_logs_seconds    = 5
max_binlog_size = 10M

Works for me on mysql 5.7 and mysql 8.0.

@xmeunier
Copy link

xmeunier commented Feb 3, 2022

Hello,

I still have the issue with php54 and mysql57

PHPVERSION=php54
DATABASE=mysql57

My configuration is very basic, i use defaults ports.
and my php code:

$myhote="localhost"; 
$myuser="root"; 
$mypass="tiger";
$base_id = mysql_connect($myhote,$myuser,$mypass); 

And i have the following issue:

image

I tried with localhost and 127.0.0.1 even with "database" (like phpmyadmin) but still not working

The lamp database locker is correctly launched:

xxxx@DESKTOP-xxxx:~/pronoweb$ docker-compose ps
     Name                    Command               State                    Ports                  
---------------------------------------------------------------------------------------------------
lamp-mysql57      docker-entrypoint.sh mysqld      Up      127.0.0.1:3306->3306/tcp, 33060/tcp     
lamp-php54        /usr/sbin/apache2ctl -D FO ...   Up      0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
lamp-phpmyadmin   /docker-entrypoint.sh apac ...   Up      0.0.0.0:8080->80/tcp                    
lamp-redis        docker-entrypoint.sh redis ...   Up      127.0.0.1:6379->6379/tcp 

@oveien
Copy link

oveien commented May 14, 2022

I had the problem in windows that mysql ignored all config files because they were world readable (Because of exported from Windows).

As I have no interest in accessing the database datafiles on the host machine, I added a database volume to get persistent database data.

Under database in docker-compose.yml:

\#     - ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
      - databasedata:/var/lib/mysql

Added to end of docker-compose.yml:

volumes:
  databasedata:

@MrOffline77
Copy link
Collaborator

MrOffline77 commented May 14, 2022

Hi all,
finally I was also able to reproduce this issue an fix it for all time :). The above Method from @oveien should work too.
The issue occurs only, if you use wsl2 mounted volumes from Windows.
To solve the issue you can follow these Steps:

@wsl2

sudo -i
echo "[automount]" >> /etc/wsl.conf
echo 'options = "metadata"' >> /etc/wsl.conf

@PowerShell

wsl --shutdown

@wsl2

sudo rm -rf ./data/mysql/*

Restart your Compose stack.

@MrOffline77 MrOffline77 pinned this issue Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants