Initialising a mysql database and persist data using Docker compose - mysql

I am trying to run a web application that uses two docker containers: one contains the application code and the other container is a mysql database instance.
I am trying to populate the db with an sql file and also try to persist the database data through a volume. I am encountering an issue with the sql init file being copied into the mysql container but not being executed.
This is how my docker-compose.yml looks like:
version: "3.7"
services:
db:
image: mysql:8.0.19
command: '--default-authentication-plugin=mysql_native_password'
restart: always
volumes:
- db-data:/var/lib/mysql
- ./db:/docker-entrypoint-initdb.d/:ro
environment:
- MYSQL_ROOT_PASSWORD=password
networks:
- backend
app:
build: app
restart: always
depends_on:
- db
ports:
- 5000:5000
networks:
- backend
- frontend
volumes:
- ./app/src:/code
volumes:
db-data:
networks:
backend:
frontend:
And this is the log when starting the mysql container
2021-04-17 12:34:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2021-04-17 12:34:01+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-04-17 12:34:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2021-04-17T12:34:01.466444Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2021-04-17T12:34:01.466615Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
2021-04-17T12:34:01.891144Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-04-17T12:34:01.895163Z 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.
2021-04-17T12:34:01.916128Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2021-04-17T12:34:02.051164Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
It does not look like the init.sql file is being executed. Also from the mysql container CLI I can see that the 'init.sql' file has been copied.
# cd docker-entrypoint-initdb.d
# ls
init.sql
# mysql -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| example |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
I am quite new to Docker and Docker compose but I cannot figure out how to make this work.

Related

bind mount to mysql docker container not working

I have a mysql docker container with container_name=mysql1. When I run docker exec -it mysqlsh and look at the files using ls command, i see the following files.
bin boot dev docker-entrypoint-initdb.d entrypoint.sh etc healthcheck.sh home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
I want to bind mount some of these folders in my host machine, inside the directory where the docker-compose file is being run from.
version: '3.9'
services:
mysql1:
container_name: mysql1
image: mysql/mysql-server
ports:
- '3306:3306'
environment:
- MYSQL_ROOT_PASSWORD = 'root'
volumes:
- ./db:/etc
But tis is giving me the following error:
[+] Running 2/0
⠿ Network poc_1_default Created 0.0s
⠿ Container mysql1 Created 0.0s
Attaching to mysql1
mysql1 | [Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
mysql1 | [Entrypoint] Initializing database
mysql1 | [Entrypoint] No password option specified for new database.
mysql1 | [Entrypoint] A random onetime password will be generated.
mysql1 | 2022-02-05T16:36:18.356881Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 18
mysql1 | 2022-02-05T16:36:18.359651Z 0 [ERROR] [MY-010124] [Server] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
mysql1 | 2022-02-05T16:36:18.359664Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
mysql1 | 2022-02-05T16:36:18.359700Z 0 [ERROR] [MY-010119] [Server] Aborting
mysql1 | 2022-02-05T16:36:18.359754Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28) MySQL Community Server - GPL.
mysql1 exited with code 1
What is happening and how do I fix this?

lower_case_table_names error for Docker + MySQL 8.0.26 based project on Ubuntu 20.04 Server(AWS EC2)

I am trying to configure my Django + MySQL(8.0.26) project on Ubuntu 20.04 based AWS EC2 server with Docker Compose. However, MySQL database container is not working because of lower_case_table_names. These are a few solutions solution1, solution2, solution3 which I've already tried but have not been able to find the solution.
I have created a sample project based on this YouTube tutorial which is successfully running on my local machine(macOS 11.4).
docker-compose.yml
version: '3.8'
services:
db:
image: mysql:8.0.26
restart: always
command: --lower_case_table_names=1
environment:
- MYSQL_DATABASE=tutorialdb
- MYSQL_USER=chitrang
- MYSQL_PASSWORD=test123
- MYSQL_ROOT_PASSWORD=test123
ports:
- "3307:3306"
volumes:
- ./dbdata:/var/lib/mysql
backend:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db
Error Log:
db_1 | 2021-08-20 01:01:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
db_1 | 2021-08-20 01:01:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2021-08-20 01:01:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
db_1 | 2021-08-20T01:01:51.247142Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.26) starting as process 1
db_1 | 2021-08-20T01:01:52.809303Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db_1 | 2021-08-20T01:01:56.262851Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db_1 | 2021-08-20T01:01:56.320513Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('2').
db_1 | 2021-08-20T01:01:56.321126Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
db_1 | 2021-08-20T01:01:56.321630Z 0 [ERROR] [MY-010119] [Server] Aborting
db_1 | 2021-08-20T01:01:56.867684Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.26) MySQL Community Server - GPL.
I have tried to set all the three possible values 0|1|2 for lower_case_table_names in a docker-compose.yml file but error message is similar each time.
I guess solution could be simple but since this my first Backend + DevOps project I might not able to figure it out easily. Moreover, it seems this issue is common and has been faced by many developers so in my opinion either MySQL or Ubuntu team should have resolved it.
Try this, It worked for me:
https://gist.github.com/feltnerm/bb6e23f531803896ca1e
version: '3.8'
services:
db:
image: mysql:8.0.26
restart: always
command: --lower_case_table_names=0
environment:
- MYSQL_DATABASE=tutorialdb
- MYSQL_USER=chitrang
- MYSQL_PASSWORD=test123
- MYSQL_ROOT_PASSWORD=test123
ports:
- "3307:3306"
volumes:
- ./data/initdb.d:/docker-entrypoint-initdb.d
- ./data/mysql:/var/lib/mysql
backend:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db

Docker MySQL container not binding to local port correctly

I'm trying to connect my local 3306 to my docker containers 3306 using docker-compose. This was all working correctly until I encountered an error with MySQL when I tried changing a table name using workbench. Since then I've been unable to connect back to the container with the correct data.
Here is my docker-compose.yml:
version: "3.3"
services:
web_old:
build:
context: ./
dockerfile: ./html/Dockerfile
container_name: mackglobal_old
depends_on:
- db
volumes:
- ./:/var/www
# - ./config/000-default.conf:/etc/apache2/000-default.conf
ports:
- 8000:80
db:
container_name: mysql8_old
image: mysql:8.0.23
environment:
MYSQL_USER: "admin" # same as production so when we create views it doesnt cause definer errors
MYSQL_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "root"
volumes:
- ./mysql:/var/lib/mysql
- ./my.cnf:/etc/mysql/conf.d/my.cnf
ports:
- "3306:3306"
# command: mysqld --innodb_force_recovery=6 # USE THIS LINE IF THE MYSQL CONTAINER CRASHES TO RECOVER DATA IN READ
When connecting to the database in my application I am met with this PHP PDO error:
Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'admin'#'172.18.0.3' (using password: YES)
When I connect to the mysql instance inside the docker container I am able to access the server using the username and password in the docker-compose file and all of my databases and tables are inside the instance. But when connecting to the instance inside workbench every query I make is met with:
Error Code: 1046. No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.
and when running SHOW databases; I only get information_schema
Here are the details I've been using to connect to the instance:
Hostname: MacBook-Pro-2.local (also tried: localhost, 127.0.0.1)
Port: 3306 (I've also changed the port to 3307 in the compose file and get the same errors)
Username: admin
Password: root
Here is my.cnf:
[mysqld]
default_time_zone='+00:00'
sql_mode=""
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES UTF8;'
innodb-flush-log-at-trx-commit=0
lower_case_table_names=2
and here is the log when running docker-compose up --build:
mysql8_old | 2021-02-16 20:15:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
mysql8_old | 2021-02-16 20:15:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql8_old | 2021-02-16 20:15:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
mysql8_old | 2021-02-16T20:15:39.468943Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 1
mysql8_old | 2021-02-16T20:15:39.506466Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql8_old | 2021-02-16T20:15:40.895843Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql8_old | 2021-02-16T20:15:41.681805Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql8_old | 2021-02-16T20:15:41.848877Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql8_old | 2021-02-16T20:15:41.849540Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql8_old | 2021-02-16T20:15:41.867833Z 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.
mysql8_old | 2021-02-16T20:15:42.028150Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
I should also note that the last environment I used was mysql:8.0.21 but I arrived at the same errors
Any help is greatly appreciated
Addition:
I've also tried restarting docker service and my laptop as well
When running network utility on port 3306 while containers are active:
Port scanner
EDIT:
Turns out my folder which holds the mysql data ./mysql in my docker compose file is now corrupt (without error) and I'm still unable to access anything in recovery mode. Luckily I had a backup but I lost all my recent changes that I made. I still am unsure what went wrong so I'm leaving this unsolved
In my docker-compose.yml, I made my mysql container like this:
mysql8-service:
image: mysql:8
container_name: mysql8-container
ports:
- "4306:3306"
volumes:
- ./mysql:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always # always restart unless stopped manually
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: secret
MYSQL_PASSWORD: secret
networks:
- nginx-php74-mysql8-node
It make me able to save my database in the folder of my app, and my credentials are good.

Why MySQL Container Keeps Restarting on Windows 10 Home with WSL 2?

I am trying to set up a Laravel development environment on my local machine, but my MySQL container keeps on restarting.
Using: Windows 10 Home with WSL2 and Docker Desktop
docker-compose.yml
version: '3'
networks:
laravel:
services:
web:
image: nginx:stable-alpine
container_name: nginx
ports:
- "80:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- phpfpm
- db
networks:
- laravel
db:
image: mysql:8.0.22
container_name: mysql
restart: always
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
networks:
- laravel
phpfpm:
build:
context: .
dockerfile: Dockerfile
container_name: phpfpm
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
phpmyadmin:
image: phpmyadmin:5-fpm-alpine
container_name: phpmyadmin
restart: always
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
networks:
- laravel
Dockerfile
FROM php:7.2-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
Nginx (default.conf)
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/laravelapp/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Source: https://serverfault.com/questions/935096/docker-nginx-php-fpm-error-emerg-11-host-not-found-in-upstream
resolver 127.0.0.11; # docker's internal fixed IP address
set $upstream phpfpm:9000;
# nginx will now start if host is not reachable
fastcgi_pass $upstream;
# Source End
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
# gzip_static on;
}
}
docker-compose ps or docker deskop shows that mysql container status as restarting.
It restarts once in a while, but stops again. It seems like something is terribly wrong when I look at the log file, but I couldn't make sense.
mysql container log
2020-11-07 17:09:27+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.22-1debian10 started.
2020-11-07 17:09:28+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-11-07 17:09:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.22-1debian10 started.
2020-11-07T17:09:28.627271Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 1
2020-11-07T17:09:28.634780Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2020-11-07T17:09:28.654292Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-07T17:09:30.967703Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Table 'mysql.plugin' doesn't exist
2020-11-07T17:09:31.108803Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.
2020-11-07T17:09:31.187838Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2020-11-07T17:09:31.251299Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-07T17:09:31.304178Z 0 [Warning] [MY-000054] [Server] World-writable config file './auto.cnf' is ignored.
2020-11-07T17:09:31.305509Z 0 [Warning] [MY-010107] [Server] World-writable config file './auto.cnf' has been removed.
2020-11-07T17:09:31.306123Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 00514c52-211c-11eb-bbbd-0242ac170002.
2020-11-07T17:09:31.415490Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-07T17:09:31.439838Z 0 [Warning] [MY-013595] [Server] Failed to initialize TLS for channel: mysql_main. See below for the description of exact issue.
2020-11-07T17:09:31.440013Z 0 [Warning] [MY-010069] [Server] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2020-11-07T17:09:31.444031Z 0 [Warning] [MY-010284] [Server] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-11-07T17:09:31.445904Z 0 [Warning] [MY-010284] [Server] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-11-07T17:09:31.520973Z 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.
2020-11-07T17:09:31.521733Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2020-11-07T17:09:31.522162Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-001146 - Table 'mysql.component' doesn't exist
2020-11-07T17:09:31.522393Z 0 [Warning] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-003543 - The mysql.component table is missing or has an incorrect definition.
2020-11-07T17:09:31.523156Z 0 [ERROR] [MY-010326] [Server] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2020-11-07T17:09:31.523377Z 0 [ERROR] [MY-010952] [Server] The privilege system failed to initialize correctly. For complete instructions on how to upgrade MySQL to a new version please see the 'Upgrading MySQL' section from the MySQL manual.
2020-11-07T17:09:31.523987Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-11-07T17:09:32.995214Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.22) MySQL Community Server - GPL.
Instead of mapped volumes for data persistence, I used the managed volume and it is not crashing anymore
Previous
db:
image: mysql:8.0.22
container_name: mysql
restart: always
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
networks:
- laravel
Now
db:
image: mysql:8.0.22
container_name: mysql
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
networks:
- laravel
volumes:
db_data: {}
I posted that question when I was starting with docker... After some research, I found out that the main culprit is that the different Linux distro used different user id for the same user name. So basically the permissions problem.
Please read this article if that makes sense to you... https://medium.com/swlh/wordpress-deployment-with-nginx-php-fpm-and-mariadb-using-docker-compose-55f59e5c1a
I have to remove the current user from ubuntu and add the user that matches the alpine user. That's the distro I was using at that time.
Probably that's the gotcha I think... if you are using ubuntu and using docker image of alpine Linux... then the user name and user id may vary...
The article I have referenced shows how to remove users from your current Linux distro and add the same user with a different user id.

Why is doccker using cached mysql data instead of latest mysql dump?

I have a docker image for mysql datbase.
The first time I made this work I backed up my db to a .sql file and then from my docker-compose I
build up the dabase.
Now however I have made some updates, created a new .sql file and again through the docker-compose I thought I would get my new data and new changes.
my docker-comose file:
services:
mysql:
image: mysql:latest
container_name: mysqldb
cap_add:
- SYS_NICE # CAP_SYS_NICE
# container_name: my_very_special_server
ports:
- 3307:3306
environment:
MYSQL_DATABASE: wedding
MYSQL_ROOT_PASSWORD: SomeRootPassword1!
MYSQL_USER: someuser
MYSQL_PASSWORD: Password1!
volumes:
- ./dbScript/Dump20201018.sql:/docker-entrypoint-initdb.d/Dump20201018.sql
- db_data:/var/lib/mysql
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: dev_pma
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3307
PMA_ARBITRARY: 1
restart: always
ports:
- 8183:80
server:
container_name: weddingapp_server
build: ./weddingApp-Be
depends_on:
- mysql
environment:
MYSQL_HOST_IP: mysql
ports:
- 4000:4000
links:
- mysql
command: npm run dev
client:
container_name: weddingapp_client
build: ./weddingApp-Fe
ports:
- 3001:3000
environment:
- CHOKIDAR_USEPOLLING=true
tty: true
volumes:
db_data:
After the build was finished and I spinned it up I saw that my new data wasn't showing up, I still had the old data cached somewhere?
I checked the logs for my mysql image and got this:
2020-10-18 20:46:59+00:00 [Note] [Entrypoint]: Entrypoint script for
MySQL Server 8.0.21-1debian10 started. 2020-10-18 20:46:59+00:00
[Note] [Entrypoint]: Switching to dedicated user 'mysql' 2020-10-18
20:46:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server
8.0.21-1debian10 started. 2020-10-18T20:46:59.686360Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as
process 1 2020-10-18T20:46:59.693458Z 1 [System] [MY-013576] [InnoDB]
InnoDB initialization has started. 2020-10-18T20:46:59.987115Z 1
[System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-10-18T20:47:00.115947Z 0 [System] [MY-011323] [Server] X Plugin
ready for connections. Bind-address: '::' port: 33060, socket:
/var/run/mysqld/mysqlx.sock 2020-10-18T20:47:00.196070Z 0 [Warning]
[MY-010068] [Server] CA certificate ca.pem is self signed.
2020-10-18T20:47:00.196193Z 0 [System] [MY-013602] [Server] Channel
mysql_main configured to support TLS. Encrypted connections are now
supported for this channel. 2020-10-18T20:47:00.200913Z 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. 2020-10-18T20:47:00.219538Z 0 [System]
[MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version:
'8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL
Community Server - GPL.
I am fairly new to docker and honestly I don't know what I am doing wrong. Any ideas?
initdb scripts are only executed when your data directory (/var/lib/mysql) is empty.
Your data are not cached, but persisted to your host using your volume. So if this is a development work, you can simply delete the contents of db_data volume (or deleting and creating it again):
docker volume rm db_data
docker volume create db_data