docker-library / mysql

Docker Official Image packaging for MySQL Community Server
https://dev.mysql.com/
GNU General Public License v2.0
2.47k stars 2.2k forks source link

Permission issues in mysql - container crashing #1006

Closed gabrielgomessds closed 11 months ago

gabrielgomessds commented 1 year ago

I've been having this problem for a week and I don't know how to solve it. I started a small laravel project with Docker and Docker's mysql doesn't work at all. It keeps crashing on its own, when running docker logs my-container, I get these errors: Unable to change permissions for file 'private_key.pem.temp' (OS errno 1 - Operation not permitted)

My settings: .env:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel_ead
DB_USERNAME=sail
DB_PASSWORD=root

Docker-compose.yml:

mysql:
           image: mysql:8.0
           restart: unless-stopped
           environment:
               MYSQL_DATABASE: ${DB_DATABASE}
               MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
               MYSQL_PASSWORD: ${DB_PASSWORD}
               MYSQL_USER: ${DB_USERNAME}
           command: ["--disable-partition-engine-check"]
           volumes:
               - ./.docker/mysql/dbdata:/var/lib/mysql
                 - mysql-data:/var/lib/mysql
           ports:
               - 3388:3306
           networks:
               - laravel-eti

I've tried changing the ports, I've tried changing the DB_HOST to 127.0.0.1 for localhost, I've tried clearing the cache, I've installed and tried using Sail, I've tried deleting the entire project and starting over, I've uninstalled and reinstalled docker, I've changed the version of mysql I started with 5.7 and I'm using 8.0 and it seems that this has made the situation worse. I'm using Windows (wsl2). Before I got this error every time I ran php Crafter Migrate - error: SQLSTATE[HY000][1130] Host '172.20.0.6' does not have permission to connect to this MySQL server. I am using windows 10 with WSL2

LaurentGoderre commented 1 year ago

It won't start with version 8 and the --disable-partition-engine-check flag because it was removed in version 8. Your compose works (after fixing the whitespace in the volumes) in version 5.7 with the flag and version 8 with the command removed.

gabrielgomessds commented 1 year ago

unfortunately that's not it. But it seems like there is something wrong in mysql when I try to use command they don't work like this:

mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
LaurentGoderre commented 1 year ago

Do you try to connect from the host to the container mysql or another container to the container mysql? Also do you wait a little bit for the db to initialize?

tianon commented 11 months ago

MySQL translates "localhost" to "use the unix socket at the default path", so if you actually wanted to connect to a server running in Docker from your host, you'll have to use something like 127.0.0.1 explicitly instead.

gabrielgomessds commented 11 months ago

After two weeks of hard work I discovered the problem. I was using docker commands in VScode, but before that the project must be opened in the Windows terminal, access WSL, and then open the project. That was the problem