mysqldockerdocker-composedockerfileaccess-denied

Access Denied with Mysql Database and docker-compose


I have a MYSQL database setup with a Dockerfile and a docker-compose.yml like so:

Dockerfile:

FROM mysql:8.0.32

COPY ector_2022-02-24.sql /var/app/current/ector_2022-02-24.sql
COPY insert_user.sql /var/app/current/insert_user.sql

docker-compose.yml:

version: '3'
services:
  mysql:
    platform: linux/x86_64
    container_name: ector-api-db
    build:
      context: .
      dockerfile: docker/mysql/Dockerfile
    environment:
      - MYSQL_ROOT_USER=root
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=testuser
      - MYSQL_PASSWORD=testuser
      - MYSQL_DATABASE=test
    ports:
      - 3306:3306

I build and up my docker-compose:

Building mysql
[+] Building 1.6s (9/9) FINISHED                                                                                                                                                           
 => [internal] load build definition from Dockerfile                                                                                                                                  0.0s
 => => transferring dockerfile: 37B                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/mysql:8.0.32                                                                                                                       1.5s
 => [auth] library/mysql:pull token for registry-1.docker.io                                                                                                                          0.0s
 => [internal] load build context                                                                                                                                                     0.0s
 => => transferring context: 78B                                                                                                                                                      0.0s
 => [1/3] FROM docker.io/library/mysql:8.0.32@sha256:f496c25da703053a6e0717f1d52092205775304ea57535cc9fcaa6f35867800b                                                                 0.0s
 => CACHED [2/3] COPY ector_2022-02-24.sql /var/app/current/ector_2022-02-24.sql                                                                                                      0.0s
 => CACHED [3/3] COPY insert_user.sql /var/app/current/insert_user.sql                                                                                                                0.0s
 => exporting to image                                                                                                                                                                0.0s
 => => exporting layers                                                                                                                                                               0.0s
 => => writing image sha256:10d50b969237ab2122ecf26b16621fdbf3d45d524e8eb5c068cfa8bddf5a5de7                                                                                          0.0s
 => => naming to docker.io/library/ector-api_mysql                                                                                                                                    0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Successfully built 10d50b969237ab2122ecf26b16621fdbf3d45d524e8eb5c068cfa8bddf5a5de7
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating ector-api-db ... done
Attaching to ector-api-db
ector-api-db | 2023-05-05 15:38:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
ector-api-db | 2023-05-05 15:38:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
ector-api-db | 2023-05-05 15:38:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
ector-api-db | 2023-05-05 15:38:38+00:00 [Note] [Entrypoint]: Initializing database files
ector-api-db | 2023-05-05T15:38:38.470162Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
ector-api-db | 2023-05-05T15:38:38.470243Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.32) initializing of server in progress as process 81
ector-api-db | 2023-05-05T15:38:38.476658Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
ector-api-db | 2023-05-05T15:38:38.953796Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
ector-api-db | 2023-05-05T15:38:40.201221Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
ector-api-db | 2023-05-05 15:38:43+00:00 [Note] [Entrypoint]: Database files initialized
ector-api-db | 2023-05-05 15:38:43+00:00 [Note] [Entrypoint]: Starting temporary server
ector-api-db | 2023-05-05T15:38:43.388919Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
ector-api-db | 2023-05-05T15:38:43.390341Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 126
ector-api-db | 2023-05-05T15:38:43.406548Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
ector-api-db | 2023-05-05T15:38:43.593535Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
ector-api-db | 2023-05-05T15:38:43.889082Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
ector-api-db | 2023-05-05T15:38:43.889189Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
ector-api-db | 2023-05-05T15:38:43.890503Z 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.
ector-api-db | 2023-05-05T15:38:43.911793Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
ector-api-db | 2023-05-05T15:38:43.912017Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
ector-api-db | 2023-05-05 15:38:43+00:00 [Note] [Entrypoint]: Temporary server started.
ector-api-db | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
ector-api-db | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
ector-api-db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
ector-api-db | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
ector-api-db | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
ector-api-db | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
ector-api-db | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
ector-api-db | 2023-05-05 15:38:47+00:00 [Note] [Entrypoint]: Creating database ector
ector-api-db | 2023-05-05 15:38:47+00:00 [Note] [Entrypoint]: Creating user ector
ector-api-db | 2023-05-05 15:38:47+00:00 [Note] [Entrypoint]: Giving user ector access to schema ector
ector-api-db | 
ector-api-db | 2023-05-05 15:38:47+00:00 [Note] [Entrypoint]: Stopping temporary server
ector-api-db | 2023-05-05T15:38:47.684338Z 13 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.32).
ector-api-db | 2023-05-05T15:38:49.415465Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32)  MySQL Community Server - GPL.
ector-api-db | 2023-05-05 15:38:49+00:00 [Note] [Entrypoint]: Temporary server stopped
ector-api-db | 
ector-api-db | 2023-05-05 15:38:49+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
ector-api-db | 
ector-api-db | 2023-05-05T15:38:50.007520Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
ector-api-db | 2023-05-05T15:38:50.008558Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
ector-api-db | 2023-05-05T15:38:50.016345Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
ector-api-db | 2023-05-05T15:38:50.152376Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
ector-api-db | 2023-05-05T15:38:50.356427Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
ector-api-db | 2023-05-05T15:38:50.356476Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
ector-api-db | 2023-05-05T15:38:50.358391Z 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.
ector-api-db | 2023-05-05T15:38:50.380307Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
ector-api-db | 2023-05-05T15:38:50.380545Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

Then I try to connect to my DB using this command:
mysql -u testuser -p -h 127.0.0.1 -P 3306

But I get this error:

ERROR 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: NO)

I tried removing the password, same error. I tried using the root user to log in, same error.

I tried to remove my docker image like so:

docker-compose rm -v

and building again, same error.

I don't know what else to do.


Solution

  • It seems the issue came from another mysql instance that would start as soon as I started my computer. I ditched it and now it works perfectly. Sorry for the inconvenience ! And thank you for your help.