I'm getting issue while running docker compose up , You can see my docker-compose.yaml file that I wrote for running the web API with MySQL db. I've also attached the error I'm facing currently. It'll be a great help if you can help me in this regard. thanks.
version: '3'
services:
app:
container_name: web_api
build: .
ports:
- 8080:5000
restart: on-failure
volumes:
- api:/usr/src/app/
depends_on:
- webapi-mysql
networks:
- webapi
webapi-mysql:
image: mysql:8.0.26
container_name: db_mysql
ports:
- 3308:3306
environment:
- MYSQL_ROOT_HOST=${DB_HOST}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_NAME}
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
volumes:
- database_mysql:/var/lib/mysql
networks:
- webapi
volumes:
api:
database_mysql:
# Networks to be created to facilitate communication between containers
networks:
webapi:
driver: bridge
Error is coming up in my CLI, as follows
Attaching to db_mysql, web_api
db_mysql | 2021-11-08 13:20:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
db_mysql | 2021-11-08 13:20:28+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_mysql | 2021-11-08 13:20:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
db_mysql | 2021-11-08 13:20:28+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user
db_mysql | Remove MYSQL_USER="root" and use one of the following to control the root user password:
db_mysql | - MYSQL_ROOT_PASSWORD
db_mysql | - MYSQL_ALLOW_EMPTY_PASSWORD
db_mysql | - MYSQL_RANDOM_ROOT_PASSWORD
web_api | 2021/11/08 13:20:31 dial tcp 127.0.0.1:3306: connect: connection refused
db_mysql exited with code 1
web_api exited with code 1
You should change the db configuration in your app to connect to webapi-mysql instead of 127.0.0.1. Every container gets its own unique address. Docker will create a fake DNS record for webapi-mysql that points to the correct IP address at that time.
Related
I have my docker compose as follows but am getting an operation not permitted mbind issue. It's been awhile but as far as I remember it was seeding with the db/init before. I have 2 sql files in there that I exported from a seeded db in the past via MySQL Workbench.
db_1 | 2022-05-17T03:52:16.766919Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
db_1 | mbind: Operation not permitted
db:
command: '--default-authentication-plugin=mysql_native_password'
environment:
- MYSQL_DATABASE=investing
- MYSQL_ROOT_PASSWORD=777
image: mysql:8.0.28
ports:
- "3307:3306"
restart: on-failure
volumes:
- "./db/init:/tmp/docker-entrypoint-initdb.d"
Very curious thing but apparently I now needed to add security options to docker compose. I haven't upgraded docker but I did upgrade my Linux OS. I can't think of any other major system changes to prompt the issue.
security_opt:
- seccomp:unconfined
db:
command: '--default-authentication-plugin=mysql_native_password'
environment:
- MYSQL_DATABASE=investing
- MYSQL_ROOT_PASSWORD=777
image: mysql:8.0.28
ports:
- "3307:3306"
restart: on-failure
security_opt:
- seccomp:unconfined
volumes:
- "./db/init:/tmp/docker-entrypoint-initdb.d"
My db/init is still no longer seeding but that may be out of the scope of this question.
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
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
I am using Docker-Compose and wait-for-it to start my backend with Node.js once the MySQL service is ready to receive connections. My problem is that the script does not realize the connection is ready by itself. I can make it work if I set the timeout to 20s since MySQL would be running by then, but that could change in different environments and the app would crash if it took more time for a specific environment. I want it to check it periodically since I think it is the right thing to do.
This is my docker-compose.yml:
version: "3.8"
services:
app:
image: pfmc
ports:
- 4005:4005
working_dir: /usr/src/app
command: sh -c './wait-for-it.sh -t 0 db:3306 -- npm start'
environment:
MYSQL_ROOT_PASSWORD: pfmc123
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: pfmc123
MYSQL_DATABASE: pfmc
mysql:
image: mysql:5
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./db-startup:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: pfmc123
MYSQL_DATABASE: pfmc
The logs:
app_1 | wait-for-it.sh: waiting for db:3306 without a timeout
mysql_1 | 2020-05-25 19:59:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
mysql_1 | 2020-05-25 19:59:58+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1 | 2020-05-25 19:59:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
mysql_1 | 2020-05-25 19:59:58+00:00 [Note] [Entrypoint]: Initializing database files
and it stays at this point:
mysql_1 | 2020-05-25T20:00:08.243448Z 0 [Note] mysqld: ready for connections.
mysql_1 | Version: '5.7.30' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
Thank you very much for your help.
You do have one issues in here: your MySQL container is a service named mysql not db you should either adapt the service to be named db or the wait-for-it invocation to poll on a connection to mysql:3306
All together, your docker-compose.yml should look like this – I added the fix with comment stating #fixme:
version: "3.8"
services:
app:
image: pfmc
ports:
- 4005:4005
working_dir: /usr/src/app
command: sh -c './wait-for-it.sh -t 0 db:3306 -- npm start'
environment:
MYSQL_ROOT_PASSWORD: pfmc123
# A first #fixme is here
MYSQL_HOST: db
MYSQL_USER: root
MYSQL_PASSWORD: pfmc123
MYSQL_DATABASE: pfmc
# And a second #fixme is here
db:
image: mysql:5
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./db-startup:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: pfmc123
MYSQL_DATABASE: pfmc
I am trying to install wordpress with mysql via docker but I have communication errors between the container of the DB and the wordpress container.
here is my docker-compose.yml file
version: '3'
services:
db:
image: mysql:latest
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
links:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
If I execute the "docker-compose up -d" command and that I open the logs of the wordpress container I have this error:
...
wordpress_1 | Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2054) The server requested authentication method unknown to the client
...
I added command: '--default-authentication plugin=mysql_native_password' in the db section and i changed the mysql version to 5.7 but it did not help me solve the problem.
I also visited these discussions :
Wordpress on docker-compose no run
https://serverfault.com/questions/880773/unable-to-access-wordpress-site-created-as-a-docker-stack/880777#880777
https://github.com/docker-library/wordpress/issues/313
Thank you in advance for your proposals.
It seems that WordPress/PHP doesn't support MySQL v8 yet. Even wordpress docker image readme suggests to use MySQL v5.7. After changing mysql version to v5.7, you might notice that MySQL container crashes with an error similar to below:
...
db_1 | 2019-01-28T18:45:24.611045Z 0 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4800!
db_1 | 2019-01-28 18:45:24 0x7f00e013a740 InnoDB: Assertion failure in thread 139641736111936 in file ut0ut.cc line 942
db_1 | InnoDB: We intentionally generate a memory trap.
...
To fix this, easiest way is to delete the MySQL docker volume using docker-compose down -v. After that, docker-compose up -d should work.
If that still doesn't work, use the docker-compose example from https://hub.docker.com/_/wordpress/. Adding it here in case it gets pulled down in future.
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'