'mysql on docker: Can't start server : Bind on unix socket: Invalid argument

I have docker compose yaml:

version: "3.8"
services:
  mysql:
    image: mysql/mysql-server:8.0.27
    container_name: javanotifications_mysql
    volumes:
      - ./persistence/mysql_db:/var/lib/mysql

and after running

docker compose up

I got

[Entrypoint] MySQL Docker Image 8.0.27-1.2.6-server
[Entrypoint] Starting MySQL 8.0.27-1.2.6-server
2022-04-22T23:45:52.061082Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1
2022-04-22T23:45:52.065609Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2022-04-22T23:45:52.077805Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-04-22T23:45:52.534236Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-04-22T23:45:52.803994Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-04-22T23:45:52.804064Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-04-22T23:45:52.808602Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-04-22T23:45:52.808689Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-04-22T23:45:52.818496Z 0 [ERROR] [MY-010270] [Server] Can't start server : Bind on unix socket: Invalid argument
2022-04-22T23:45:52.818539Z 0 [ERROR] [MY-010258] [Server] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
2022-04-22T23:45:52.818778Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-04-22T23:45:54.322278Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27)  MySQL Community Server - GPL.

and container dies.

After cleaning "persistence" directory and repeating the process everything is the same

The only thing that comes to my mind is that it has some problems with /var/lib/mysql/mysql.sock, mysql doesn't like to have it (maybe) in mounted directory.

Then question comes, how to tell mysql to create it somewhere else in the container - beyond mounted directory /var/lib/mysql/?

Docker version 20.10.14, build a224086
MacBook Pro 16-inch, 2019, 2.4 GHz 8-Core Intel Core i9
macOS Big Sur version 11.6


Solution 1:[1]

You can set it vida mysqld configuration.

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock

If it doesn't work you can check this other similar question here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sergio Santiago