I am trying to run SLTs and for that i have defined mysql as a dependency in my docker-compose.yml
Platform:
networks:
- shared
image: platform
build:
context: ../../../
dockerfile: Dockerfile.slt
container_name: platform
ports:
- 7777:7777
- 1053:1053
volumes:
- /tmp/server:/tmp/server
restart: unless-stopped
env_file:
- docker.env
depends_on:
- predictiondb
predictiondb:
networks:
- shared
image: mysql:latest
restart: always
container_name: predictiondb
environment:
# Password for root access
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "prediction"
ports:
- 3306:3306
expose:
- 3306
volumes:
- predictiondb:/var/lib/mysql
After running the docker-compose.yml i am trying to connect with the mysql using my application.
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root:root#tcp(localhost:3306)/prediction")
if err != nil {
panic(err)
}
defer db.Close()
err = db.ping()
if err != nil {
log.Print(err)
}
Here i am getting the error
{"error": "dial tcp 172.18.0.2:3306: connect: connection refused"}
I have checked that mysql is running in a container using docker ps command.
I have tried connecting with mysql from my local(mysql -P 3306 --protocol=tcp -u root -p) on the port 3306 and able to connect and also able to see the prediction database created.
checked the logs of the container and mysql is running.
tried using root:root#tcp(predictiondb:3306)/prediction, but still same error.
mysql docker logs
2022-07-20T15:49:26.367485Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.29).
2022-07-20T15:49:27.706467Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
2022-07-20 15:49:28+00:00 [Note] [Entrypoint]: Temporary server stopped
2022-07-20 15:49:28+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2022-07-20T15:49:28.598959Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-20T15:49:28.606127Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-20T15:49:28.712782Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-20T15:49:28.928948Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-20T15:49:28.929033Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-20T15:49:28.931482Z 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.
2022-07-20T15:49:28.972456Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-07-20T15:49:28.972721Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
My application is running in another docker container, i am using same docker-compose.yml
Any help will be appreciated.
When your application is running in a container started by the same docker-compose file you cannot access the exposed port from localhost because it is visible only from the host, it cannot be accessed from another container. You need to connect to the wanted application through the container name:
db, err := sql.Open("mysql", "root:root#tcp(predictiondb:3306)/prediction")
Related
I want to create a MySQL container purely for testing/learning purposes. If possible, I don't want to deal with extra complexities such as SSL. When I use DBeaver, connecting to
server host: localhost
port: 33060
Database: mysqldb
Username: root
Pasword: secret
Driver name: MySQL
Gives me
"null, message from server: "Host '172.21.0.1' is not allowed to connect to this MySQL server"
The logs for the Docker container is:
>docker logs 20ae6
2022-08-30 03:58:16+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
2022-08-30 03:58:17+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-08-30 03:58:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-08-30T03:58:17.801333Z 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.
2022-08-30T03:58:17.803389Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2022-08-30T03:58:17.803424Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30) starting as process 1
2022-08-30T03:58:17.812663Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-30T03:58:18.068441Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-30T03:58:18.405999Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-08-30T03:58:18.406051Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-08-30T03:58:18.408437Z 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.
2022-08-30T03:58:18.434789Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-08-30T03:58:18.434883Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2022-08-30T04:00:19.018745Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.30).
2022-08-30T04:00:19.814521Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30) MySQL Community Server - GPL.
2022-08-30 04:00:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
2022-08-30 04:00:22+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-08-30 04:00:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-08-30T04:00:23.462649Z 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.
2022-08-30T04:00:23.464620Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2022-08-30T04:00:23.464649Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30) starting as process 1
2022-08-30T04:00:23.477879Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-30T04:00:23.763140Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-30T04:00:24.028665Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-08-30T04:00:24.028729Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-08-30T04:00:24.031322Z 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.
2022-08-30T04:00:24.059763Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-08-30T04:00:24.059827Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
I start it with
docker-compose up
using
docker-compose.yml:
version: '3.7'
services:
mysql:
image: mysql:8.0
restart: always
container_name: mysqldb
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: mysqldb
MYSQL_USER: mysqluser
MYSQL_PASSWORD: mysqlpw
MYSQL_ROOT_HOST: '%'
networks:
- db
command: --default-authentication-plugin=mysql_native_password
healthcheck:
test: "mysqladmin ping -h localhost"
interval: 1s
timeout: 1s
retries: 60
volumes:
- mysql:/var/lib/mysql
ports:
- '33060:3306'
networks:
db:
driver: bridge
volumes:
mysql:
I've tried adding
MYSQL_ROOT_HOST: '%'
surrounding it both with ' and ".
and I've also tried it without this.
I also tried adding
command: --default-authentication-plugin=mysql_native_password
but it doesn't care.
I can see no sign in the log that the DBeaver test connection ever reached it. However, if I give it some other port like 33065 it gives me a connection refused. It's like it reaches some Docker/Networking/Purgatorial limbo that produces no usable output.
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.
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.
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.
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