Docker-compose up -d - Database is uninitialized (but they are Init.) - mysql

I am having the problem starting up Mysql Container in Docker.
Mysql goes up and than it is constantly in restart mode.
The Error message what I got is:
[ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
You need to specify one of the following:
- MYSQL_ROOT_PASSWORD
- MYSQL_ALLOW_EMPTY_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD
[Note] [Entrypoint]: Switching to dedicated user 'mysql'
[Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started.
However, 2 of 3 vars are initialized
My docker-compose.yaml configration for Mysql is:
mysql:
build: ./.docker/mysql
restart: unless-stopped
environment:
- MYSQL_USER=app
- MYSQL_PASSWORD=123456
- MYSQL_DATABASE=app
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_ALLOW_EMPTY_PASSWORD=true
volumes:
- ./.docker/mysql/data:/var/lib/mysql
networks:
- app
ports:
- "3306:3306"
For those who think that this Post is duplicate.
I have before this post research other posts (stackoverflow), but it doesnt help me (maybe cos I am using the newest Docker version Docker Engine => v20.10.8 and those Posts are from 2016)
Docker-compose: Database is uninitialized
docker, MYSQL_ROOT_PASSWORD do not work
What did I do until now
read MySql Documentation about Env vars
try solutions from Docker-compose: Database is uninitialized and docker, MYSQL_ROOT_PASSWORD do not work
try to remove my existing mysql container and create new one with docker-compose up -d

Related

Issue with mysql in docker-compose on Mac

I have an issue when trying to use a mysql docker container as part of a docker-compose on my MacBook (2,6 GHz 6-Core Intel Core i7 under Ventura 13.0.1). Here is what my docker-compose.yml file looks like:
version: '3.1'
services:
db:
image: mysql:8.0
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
expose:
- 3306
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u ${MYSQL_USER} --password=${MYSQL_PASSWORD}
interval: 5s
timeout: 5s
retries: 55
restart: unless-stopped
flask:
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./:/var/www/
working_dir: /var/www/
command: python3 app.py
depends_on:
- "db"
restart: unless-stopped
nginx:
image: nginx:1.13.7
container_name: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./static:/var/www/html
ports:
- 80:80
depends_on:
- "flask"
restart: unless-stopped
When trying to run docker-compose up, the mysql container crashes, and I get the following error in the logs:
compose_2023-db-1 | 2023-02-09T22:33:31.523197Z 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.
compose_2023-db-1 | 2023-02-09T22:33:31.523257Z 0 [ERROR] [MY-010119] [Server] Aborting
compose_2023-db-1 | 2023-02-09T22:33:31.523345Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
As visible in my docker-compose.yml, I am not even trying to persist the database in a volume. I have actually tried, both using host file system and a docker volume, with the exact same error each time.
I have tried restarting Docker, my computer, updating Docker, removing all images and containers without success. I also tried several tags for mysql images (namely latest, 7.6 and 8.0) with the same result.
What really bugs me is that this exact same setup used to work fine until earlier today, but I am not able to tell what action caused it to start erroring out every time. More strangely, I can run a mysql container with a similar setup from with the following command:
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=db \
-e MYSQL_USER=myuser \
-e MYSQL_PASSWORD=mypass \
-v $(pwd)/db:/var/lib/mysql \
-p 3306:3306 \
mysql:5.7
It seems that I am not the only one having this type of problem according to this issue on GitHub: https://github.com/docker-library/mysql/issues/757. As suggested on the last comment and since none of the pieces of advice I could find there worked for me, I would be super grateful for any leads on how to fix this.

How to fix error "Database is uninitialized and password option is not specified"

I'm working on a Mac computer.
I tried to install a nginx server and a MySQL database with docker compose.
Here is the content docker-compose.xaml file:
version: '3'
services:
web:
image: nginx
db:
image: mysql
ports:
- "3307:3306"
environment:
- MYSQLROOT_PASSWORD=password
- MYSQL_USER=user
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=demodb
When executing the next command: docker-compose -f docker-compose.yaml up
I get the next error message:
[ERROR] [Entrypoint]: Database is uninitialized and password option is
not specified db_1 | You need to specify one of the following: db_1 |
MYSQL_ROOT_PASSWORD db_1 | - MYSQL_ALLOW_EMPTY_PASSWORD db_1 | - MYSQL_RANDOM_ROOT_PASSWORD
I will enjoy if you can help me.
It seems like you forgot an underscore in MYSQL_ROOT_PASSWORD? Change it to:
environment:
- MYSQL_ROOT_PASSWORD=password

MySQL Docker Image on Apple Silicon stuck in Entrypoint Script

I'm trying to get the official mysql docker image to run on apple silicon.
It does compose and boot up, but it only has 1 log entry and does not do anything else afterwards:
2021-08-04 14:39:12+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.35-1debian10 started.
My docker-compose file looks like this:
database:
platform: linux/amd64 // I also tried linux/x86_64
image: mysql:5.7.35
ports:
- 3306:3306
volumes:
- ./mysql/create_dbs.sql:/docker-entrypoint-initdb.d/create_dbs.sql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=cars
- MYSQL_USER=cars
- MYSQL_PASSWORD=cars
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
Is there something else that needs to be done in order to get it working?

Mysql refuses Connection to Adminer on Docker

I know this is a duplicate of this, but since that was never answered, I am re-posting this question.
I am trying to build a basic connection of php-apache and mysql containers.
docker-compose.yml
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/html
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
# Exposing the ports doesn't help either
# ports:
# - 3306:3306
environment:
MYSQL_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Dockerfile
FROM php:7.2-apache
RUN docker-php-ext-install mysqli
I run a simple docker-compose up command, and access Adminer on localhost:8080.
However, despite using the default login details, i.e
server: db
username: root
password: example
I get the error SQLSTATE[HY000] [2002] Connection refused.
Screenshot:
I think the issue might be some configuration issue on my local machine, because I couldn't use docker based LAMP stacks made by other people too.
Any help is greatly appreciated,
Thank You!
Turns out Patience was the answer.
If I wait long enough(around 4.5 minutes), the mysql container lets out a small log detail.
db_1 | 2021-03-09T08:21:03.882088Z 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.
After that the login in works.
Note: There is a similar line that is logged, but that is regarding port 0, this is 3306. Attempting a failure immediately after that fails.
One must wait for the line with port 3306.
If any of you can give me feedback or advice on how I could make my mysql container initialize faster,
I'd greatly appreciate it.

docker-compose mysql persistent data

I'm new to docker and I'm following this guide to setup my mac (the guide is for linux but is not the point) for a PHP dev env with docker-compose.
The guide is quite good and everything seems to work correctly, there is just a part that doesn't seem to work.
If you go to Step 9 — Creating a User for MySQL, I'm running docker-compose up and I have these errors so I can't access the db container.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
db | 2020-04-16T18:22:19.603226Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
db | 2020-04-16T18:22:19.603246Z 0 [ERROR] [MY-010119] [Server] Aborting
If I remove the - ./mysql/my.cnf:/etc/mysql/my.cnf from the volumes everything seem to work but then for some reason my laravel db is not created.
these command is not supposed to already create a DB?
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: root
another question is where the data is stored?
db:
...
volumes:
- dbdata:/var/lib/mysql
...
#Volumes
volumes:
dbdata:
driver: local
how it works that driver local and what is the location of it?
I just found out that the tutorial uses a wrong path, the correct path is:
- ./mysql/my.cnf:/etc/my.cnf
and not:
- ./mysql/my.cnf:/etc/mysql/my.cnf
docker-compose.yml
version: '3.7'
services:
db:
image: mysql:8.0.21
container_name: dbweb
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'deivypassword'
TZ: America/New_York
ports:
# : < MySQL Port running inside container>
- '3306:3306'
# Where our data will be persisted
volumes:
- dbweb2:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
Names our volume
volumes:
dbweb2: