I am trying to build a customize mysql docker image and start it with docker compose command as follows:
The Dockerfile content is as follows:
FROM bitnami/mysql:8.2.0-debian-11-r2
ENV TZ Asia/Muscat
COPY init_script.sh /docker-entrypoint-initdb.d/
The init_script sh file is shown below:
#!/bin/sh
mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<EOF
CREATE DATABASE IF NOT EXISTS gs_keycloak;
CREATE USER keycloak IDENTIFIED BY 'keycloakdevpassword';
GRANT CREATE ROUTINE, ALTER ROUTINE, INDEX, DROP, REFERENCES, CREATE, ALTER, INSERT, SELECT, DELETE, UPDATE ON gs_keycloak.* TO keycloak WITH GRANT OPTION;
CREATE DATABASE IF NOT EXISTS gs;
CREATE USER gs IDENTIFIED BY 'fW7j272kVGwF';
GRANT CREATE ROUTINE, ALTER ROUTINE, INDEX, DROP, REFERENCES, CREATE, ALTER, INSERT, SELECT, DELETE, UPDATE ON gs.* TO gs1 WITH GRANT OPTION;
EOF
The directory for the mysql is as follows:
The mysql image is build successfully as shown below:
However when i run docker compose up command from the docker-compose file below:
version: "3"
volumes:
mysql_data: #creates mount point on docker for mysql
driver: local
log_data: #creates mount point on docker for logs
driver: local
services:
keycloak:
image: keycloak-demo
command: start-dev
container_name: keycloak-demo-container
environment:
DB_VENDOR: MYSQL
DB_ADDR: mysql
DB_DATABASE: gs1_keycloak
DB_USER: keycloak
DB_PASSWORD: root
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: root
ports:
- "9090:8080"
depends_on:
- mysqldemo
networks:
network_demo_keyck:
mysqldemo:
image: keycloakdbs
container_name: demo-mysql
environment:
DB_GS1_PWD: root
DB_KEYCLOAK_PWD: root
MYSQL_ROOT_PASSWORD: root
ports:
- "5432:5432"
networks:
network_demo_keyck:
volumes:
- mysql_data:/var/lib/mysql
networks:
network_demo_keyck:
The following exception is thrown:
Please find below all logs mysql with exception:
024-06-11 16:27:48 mysql 16:27:48.68 INFO ==>
2024-06-11 16:27:48 mysql 16:27:48.68 INFO ==> Welcome to the Bitnami mysql container
2024-06-11 16:27:48 mysql 16:27:48.68 INFO ==> Subscribe to project updates by watching https://github.com/bitnami/containers
2024-06-11 16:27:48 mysql 16:27:48.68 INFO ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
2024-06-11 16:27:48 mysql 16:27:48.68 INFO ==>
2024-06-11 16:27:48 mysql 16:27:48.68 INFO ==> ** Starting MySQL setup **
2024-06-11 16:27:48 mysql 16:27:48.69 INFO ==> Validating settings in MYSQL_*/MARIADB_* env vars
2024-06-11 16:27:48 mysql 16:27:48.70 INFO ==> Initializing mysql database
2024-06-11 16:27:48 mysql 16:27:48.70 INFO ==> Updating 'my.cnf' with custom configuration
2024-06-11 16:27:48 mysql 16:27:48.71 INFO ==> Setting slow_query_log option
2024-06-11 16:27:48 mysql 16:27:48.73 INFO ==> Setting long_query_time option
2024-06-11 16:27:48 mysql 16:27:48.74 INFO ==> Installing database
2024-06-11 16:28:00 mysql 16:28:00.16 INFO ==> Starting mysql in background
2024-06-11 16:28:02 mysql 16:28:02.18 INFO ==> Configuring authentication
2024-06-11 16:28:02 mysql: [Warning] Using a password on the command line interface can be insecure.
2024-06-11 16:28:02 mysql 16:28:02.31 INFO ==> Running mysql_upgrade
2024-06-11 16:28:02 mysql 16:28:02.31 INFO ==> Stopping mysql
2024-06-11 16:28:04 mysql 16:28:04.33 INFO ==> Starting mysql in background
2024-06-11 16:28:22 mysql 16:28:22.36 INFO ==> Loading user's custom files from /docker-entrypoint-initdb.d
2024-06-11 16:28:22 /opt/bitnami/scripts/libmysql.sh: /docker-entrypoint-initdb.d/init_script.sh: /bin/sh^M: bad interpreter: No such file or directory
2024-06-11 16:28:22 mysql 16:28:22.37 ERROR ==> Failed executing /docker-entrypoint-initdb.d/init_script.sh
2024-06-11 16:28:22 mysql 16:28:22.37 INFO ==> Stopping mysql
2024-06-11 16:27:48 2024-06-11T12:27:48.761256Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2024-06-11 16:27:48 2024-06-11T12:27:48.762652Z 0 [System] [MY-013169] [Server] /opt/bitnami/mysql/bin/mysqld (mysqld 8.2.0) initializing of server in progress as process 43
2024-06-11 16:27:48 2024-06-11T12:27:48.780706Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-06-11 16:27:50 2024-06-11T12:27:50.121820Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-06-11 16:27:53 2024-06-11T12:27:53.229848Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2024-06-11 16:28:00 2024-06-11T12:28:00.079661Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
2024-06-11 16:28:00 2024-06-11T12:28:00.171876Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2024-06-11 16:28:00 2024-06-11T12:28:00.347076Z 0 [Warning] [MY-011068] [Server] The syntax 'skip_slave_start' is deprecated and will be removed in a future release. Please use skip_replica_start instead.
2024-06-11 16:28:00 2024-06-11T12:28:00.347145Z 0 [System] [MY-010116] [Server] /opt/bitnami/mysql/bin/mysqld (mysqld 8.2.0) starting as process 91
2024-06-11 16:28:00 2024-06-11T12:28:00.359775Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-06-11 16:28:00 2024-06-11T12:28:00.581587Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-06-11 16:28:00 2024-06-11T12:28:00.868614Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-06-11 16:28:00 2024-06-11T12:28:00.868663Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-06-11 16:28:00 2024-06-11T12:28:00.900815Z 0 [System] [MY-010931] [Server] /opt/bitnami/mysql/bin/mysqld: ready for connections. Version: '8.2.0' socket: '/opt/bitnami/mysql/tmp/mysql.sock' port: 3306 Source distribution.
2024-06-11 16:28:00 2024-06-11T12:28:00.900899Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2024-06-11 16:28:02 2024-06-11T12:28:02.321619Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.2.0).
2024-06-11 16:28:03 2024-06-11T12:28:03.386724Z 0 [System] [MY-010910] [Server] /opt/bitnami/mysql/bin/mysqld: Shutdown complete (mysqld 8.2.0) Source distribution.
2024-06-11 16:28:03 2024-06-11T12:28:03.387438Z 0 [System] [MY-015016] [Server] MySQL Server - end.
2024-06-11 16:28:04 2024-06-11T12:28:04.340059Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2024-06-11 16:28:04 2024-06-11T12:28:04.510012Z 0 [Warning] [MY-011068] [Server] The syntax 'skip_slave_start' is deprecated and will be removed in a future release. Please use skip_replica_start instead.
2024-06-11 16:28:04 2024-06-11T12:28:04.510081Z 0 [System] [MY-010116] [Server] /opt/bitnami/mysql/bin/mysqld (mysqld 8.2.0) starting as process 189
2024-06-11 16:28:04 2024-06-11T12:28:04.516014Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-06-11 16:28:04 2024-06-11T12:28:04.713135Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-06-11 16:28:04 2024-06-11T12:28:04.829443Z 4 [System] [MY-013381] [Server] Server upgrade from '80200' to '80200' started.
2024-06-11 16:28:21 2024-06-11T12:28:21.061751Z 4 [System] [MY-013381] [Server] Server upgrade from '80200' to '80200' completed.
2024-06-11 16:28:21 2024-06-11T12:28:21.237557Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-06-11 16:28:21 2024-06-11T12:28:21.237602Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-06-11 16:28:21 2024-06-11T12:28:21.253989Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2024-06-11 16:28:21 2024-06-11T12:28:21.254039Z 0 [System] [MY-010931] [Server] /opt/bitnami/mysql/bin/mysqld: ready for connections. Version: '8.2.0' socket: '/opt/bitnami/mysql/tmp/mysql.sock' port: 3306 Source distribution.
2024-06-11 16:28:22 2024-06-11T12:28:22.382456Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.2.0).
2024-06-11 16:28:27 2024-06-11T12:28:27.622590Z 0 [System] [MY-010910] [Server] /opt/bitnami/mysql/bin/mysqld: Shutdown complete (mysqld 8.2.0) Source distribution.
2024-06-11 16:28:27 2024-06-11T12:28:27.623816Z 0 [System] [MY-015016] [Server] MySQL Server - end.
Can anyone please advice what I am doing wrong? Thanks