Docker Community Forums

Share and learn in the Docker community.

After disactivating WSL2 I'm getting connection refused

Hi!
I was running Docker Desktop Community 2.2.0.4. I updated to the latest version (Docker Desktop Community 2.4.0.0) and enabled WSL2.

Then run my docker-compose.yml and everything was ok although I was having some performance issues with WSL2. Then, I decided to go back to WSL1 (due to those performance issues) disactivating WSL2 in the control panel, restarted Docker and I’m getting now the following message and can’t enable my database (mariadb):

Warning: mysqli::__construct(): (HY000/2002): Connection refused in /makedb.php on line 20
Call Stack:
0.0002 401576 1. {main}() /makedb.php:0
15.0062 403288 2. mysqli->__construct() /makedb.php:20

I tried to restart my computer but the problem remains.

If I go back to WSL2, this is issue is not happening. I’m a bit lost here.

Can anyone help me on this? Thank you in advance. Regards.

Maybe you should just reinstall Docker Desktop.

Thanks, I’m afraid it did not solve the issue :frowning:

I have the databases as volumes mounted in my local disk drive. Here is my docker-compose file (just the database part):

  db:
image: bitnami/mariadb:latest
volumes:
  - **./data/mariadb**:/bitnami/mariadb
networks: 
  - web-network
ports:
  - "3306:3306"
restart: always
environment:
  - MARIADB_ROOT_PASSWORD=xxxx
  - MARIADB_USER=xxxx
  - MARIADB_PASSWORD=xxxx
  - MARIADB_DATABASE=xxxx

After running docker-compose up I get “mariadb 09:34:33.35 INFO ==> Starting mariadb in background” and then when my web app tries to connect to the db it shows:

“Warning: mysqli::__construct(): (HY000/2002): Connection refused in /makedb.php on line 20”

I remember upgrading once from Docker Desktop Community 2.2.0.4 to 2.2.0.5 and got a similar error. That’s why I kept 2.2.0.4 for a while.

Yesterday I updated from 2.2.0.4 to the latest stable (2.4.0.0) and got this issue when running through Hyper-V (with Wsl2 activated all is working just fine although the performance is a lot worse).

Now we can see what you are doing (in general it’s a good idea to show such things from the beginning). Your problem seems to be related to the Windows folder that you mount into the database container. On Windows, you better use a named volume, especially with WSL1.
Is there a reason that you don’t use the official MariaDB image?

You’re right. Sorry I didn’t mention that.

I’m using a windows folder because a few months ago I lost my database (I was using a named volume). So I decided to map it to my windows file system to be able to run regular backups just in case I mess with it again.

Do you know if I can easily transfer the database files from my windows file system to a docker named volume?
How can I run backups on named volumes?

Note: I’M not using the official MariaDB image because when I lost the database a few month ago, I though MariaDB official image was the reason and switched to Bitnami.

Thanks in advance.

You can mount both volumes into a container

docker container run --rm -it -v /path/to/local/data:/data1 -v dbdata:/data2 debian bash

and copy the data from one to the other.

You can copy the content of a volume into a zip file as described here. With the volume of the above example this would be something like

docker container run --rm -v dbdata:/dbdata -v $(pwd):/backup debian tar cvf /backup/backup.tar /dbdata

But first you have to stop the database before you do this. And second this is not the way to create a reliable database backup. Instead you should use the mysqldump command to create your backup files.

Thanks @tekki

I can confirm that changing my database to named volume did the trick. Also the example you post was very useful. I was able to backup my database.

Best regards.