docker-library / mysql

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

Cannot access to mysql from client after initialization #1070

Closed laurafbec closed 3 months ago

laurafbec commented 3 months ago

Hi everyone, I'm trying to develop a docker compsoe file to initialize a mmysql database. The problem is that access is not allow from outside the container unless it would be restarted. First time it is launched, socket is listening at port 0, even though I indicate a different port in the my.cnf file.

2024-06-21T07:36:42.991794Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.37'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.

This is the compose file:

services:
  database:
    image: mysql:8.0
    container_name: mysql
    restart: always
    environment:
      MYSQL_DATABASE: 'flughafendb'
      MYSQL_ROOT_PASSWORD: 'root'
      MYSQL_USER: 'flughafen-user'
      MYSQL_PASSWORD: 'secret'      
      MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
    ports:
      - '3306:3306'
    healthcheck:
      test: ["CMD-SHELL", "cat /tmp/mysql-general-log.log | grep \"(1176552,330064,'11A',31286,350.95)\""]
      interval: 10s
      retries: 120
    volumes:
      - ${PWD}/docker/db/sql/flughafendb_large.sql.gz:/docker-entrypoint-initdb.d/0.sql.gz
      #- ${PWD}/docker/db/sql/flughafendb_large.sql:/tmp/flughafendb_large.sql
      - ${PWD}/docker/db/data:/var/lib/mysql
      - ${PWD}/docker/db/my.cnf:/etc/my.cnf

Thanks in advance

LaurentGoderre commented 3 months ago

Could be related to #1069 can you check the start logs to see if that warning is present?

laurafbec commented 3 months ago

Hi @LaurentGoderre, Thanks for your answer. I don't have the warning you mentioned.

These are the start logs. Thanks again

2024-06-21 07:54:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.37-1.el9 started.
2024-06-21 07:54:06+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2024-06-21 07:54:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.37-1.el9 started.
2024-06-21 07:54:07+00:00 [Note] [Entrypoint]: Initializing database files
2024-06-21T07:54:07.071886Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.37) initializing of server in progress as process 81
2024-06-21T07:54:07.095203Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-06-21T07:54:07.773439Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-06-21T07:54:09.817485Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2024-06-21 07:54:12+00:00 [Note] [Entrypoint]: Database files initialized
2024-06-21 07:54:12+00:00 [Note] [Entrypoint]: Starting temporary server
2024-06-21T07:54:13.106742Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.37) starting as process 137
2024-06-21T07:54:13.125406Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-06-21T07:54:13.396357Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-06-21T07:54:13.719595Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-06-21T07:54:13.719635Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-06-21T07:54:13.727987Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2024-06-21T07:54:13.753234Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2024-06-21T07:54:13.753261Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.37'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
2024-06-21 07:54:13+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2024-06-21 07:54:16+00:00 [Note] [Entrypoint]: Creating database flughafendb
2024-06-21 07:54:16+00:00 [Note] [Entrypoint]: Creating user flughafen-user
2024-06-21 07:54:16+00:00 [Note] [Entrypoint]: Giving user flughafen-user access to schema flughafendb
2024-06-21 07:54:16+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/0.sql.gz
laurafbec commented 3 months ago

solved!