How to connect phpmyadmin to mySql server with docker compose - mysql

I'm trying to reproduce a MAMP environment with Docker-Compose, but I can't connect the phpmyadmin service to my mariaDB database!
I have done a lot of testing, and nothing has been conclusive, at best phpmyadmin does not recognize user and password and I get the following message:
mysqli_real_connect(): (HY000/1045): Access denied for user 'root'#'172.25.0.3' (using password: YES)
Here is the docker-compose file:
version: '3'
services:
php-apache:
build:
context: ./php-apache
container_name: cbx-webserver
ports:
- 80:80 # Le port dédié à ce service
restart: always
volumes:
- ./DocumentRoot:/var/www/html
links:
- mariadb
mariadb:
image: mariadb:10.1
container_name: db-mysql
ports:
- 3306:3306
restart: always
volumes:
- ./mariadb:/docker-entrypoint-initdb.d/
- mariadb:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_USER: root
MYSQL_HOST: mariadb
MYSQL_DATABASE: mydb
myadmin:
image: phpmyadmin/phpmyadmin:4.8.1
container_name: cbx-phpmyadmin
ports:
- 8081:80
restart: always
links:
- mariadb:mysql
environment:
PMA_HOST: mydb
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: root
depends_on:
- mariadb
volumes:
mariadb:
and the actual error message

Related

Docker: Can't login in my mariadb using phpmyadmin

I am trying to build up a docker-compose file to run all components I need for my app. The app, mysql (mariadb) and phpmyadmin is running but I can't login to my database.
Following docker-compose.yml:
version: '3.7'
networks:
laravel:
services:
php:
image: php:7.4-fpm
build: .conf/php/
restart: always
ports:
- '9000:9000'
working_dir: /var/www
volumes:
- ./src:/var/www
- .conf/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
- .conf/php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini
networks:
- laravel
fpm:
image: php:7.4-fpm
restart: always
volumes:
- ./src:/var/www
networks:
- laravel
nginx:
image: nginx:latest
ports:
- 8000:80
volumes:
- ./src:/var/www
- ./var/log/nginx:/var/log/nginx
- .conf/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- laravel
mariadb:
image: mariadb:latest
ports:
- 3306:3306
volumes:
- mariadb-volume:/var/lib/mysql
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
MYSQL_DATABASE: app
MYSQL_USER: admin
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
networks:
- laravel
phpmyadmin:
image: phpmyadmin
container_name: pma
environment:
MYSQL_DATABASE: app
PMA_HOST: mariadb
depends_on:
- mariadb
ports:
- '8081:80'
networks:
- laravel
volumes:
mariadb-volume:
When I try to login, I get the following error:
mysqli::real_connect(): (HY000/1045): Access denied for user 'admin'#'172.31.0.6' (using password: YES)
I tried to find a solution.. something like set up the right env vars for mysql or set up a bridge between mysql and phpmyadmin. I did the network bridge and I can't really see the problem with my env vars.
Any clue?
System: Windows 10
Edit:
Found the problem. I just did docker-compose down -v ( -v = Remove named volumes declared in the volumes section of the Compose file and anonymous volumes )
and it worked :)
May be you can set for phpmyadmin by this command:
phpmyadmin:
image: phpmyadmin:latest
container_name: pma
restart: always
environment:
MYSQL_DATABASE: app
PMA_HOST: mariadb
depends_on:
- mariadb
ports:
- '8081:80'
networks:
- laravel

not able to connect mysql from sequel or terminal

I'm using mysql in docker. I can access docker through docker exec terminal. But I can't access it outside through my regular terminal or sequel ace.
What I'm getting in in sequel ace and in regular terminal
Access denied
Unable to connect to host 127.0.0.1 because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'crowdtank'#'localhost' (using password: YES)
Access denied for user 'crowdtank'#'localhost' (using password: YES)
Terminal command and output for access attempt
ERROR 1045 (28000): Access denied for user 'crowdtank'#'localhost' (using password: YES)
My docker code
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: crowdtank
MYSQL_USER: crowdtank
MYSQL_PASSWORD: crowdtank
MYSQL_ROOT_PASSWORD: crowdtank
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www
ports:
- "9000:9000"
networks:
- laravel

How to fix "Access denied for user 'root'#'172.22.0.4' (using password: YES)" when connecting to mysql container?

I'm creating a laravel project in a docker container, along with MySQL and phpmyadmin, when trying to migrate (or access the database from phpmyadmin) I get access denied error.
I've tried several SOF solutions but none of them worked, also tried ones in GitHub issues.
here is my docker-compose.yml
version: "3"
services:
web:
container_name: ${APP_NAME}_web
build:
context: ./docker/web
ports:
- 9000:80
volumes:
- ./:/var/www/app
networks:
- mynet
db:
image: mysql:5.7
container_name: db
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laracocodb
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- mysqldata:/var/lib/mysql/
networks:
- mynet
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpma
links:
- db:db
ports:
- 9191:80
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
PMA_HOST: db
networks:
- mynet
networks:
mynet:
driver: bridge
volumes:
mysqldata:
driver: local
no matter where I access the database (from db container bash, from phpmyadmin index page or from the web service when trying to migrate the database), the error is always access denied
I have also run into this problem many times, by default MySQL allows root to be accessed by localhost user that means even if you have opened the port 3306:3306, you will still need to add the user.
Follow these commands and the error will resolve!
https://stackoverflow.com/a/11225588

Authentication error using phpmyadmin and docker-compose

I'm trying to user docker-compose for mysql and phpmyadmin, but I'm getting an authentication error when trying to log in to phpmyadmin.
I've tried several configurations on the yaml file, but without any success.
version: '3'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: root
MYSQL_PASSWORD: admin
MYSQL_ROOT_PASSWORD: admin
volumes:
- my-db:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db
ports:
- 8080:80
restart: always
environment:
PMA_USER: root
PMA_PASSWORD: admin
volumes:
my-db: {}
When I try logging in to phpmyadmin i get the following errors:
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
I tried to change the yml to:
version: '3'
services:
db:
image: mysql:57
restart: always
environment:
After this, the container no longer starts, and it gives the following message:
docker_db_1 exited with code 1
This works fine:
version: '3'
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: root
MYSQL_PASSWORD: admin
MYSQL_ROOT_PASSWORD: admin
volumes:
- my-db:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db
ports:
- 8080:80
restart: always
environment:
PMA_USER: root
PMA_PASSWORD: admin
volumes:
my-db: {}
Remember to delete the volume before running (in case you run into issues).
I just copied this code in docker-compose.yml
version: '3'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: root
MYSQL_PASSWORD: admin
MYSQL_ROOT_PASSWORD: admin
volumes:
- my-db:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db
ports:
- 8080:80
restart: always
environment:
PMA_USER: root
PMA_PASSWORD: admin
volumes:
my-db: {}
and ran the command docker stack deploy -c docker-compose.yml mysqllab
This is the result
enter image description here

Docker can't connect to MySQL running docker-compose up

I am using this Docker config: https://github.com/romaricp/kit-starter-symfony-4-docker
I start the environment by using:
docker-compose build
followed by:
docker-compose up -d
Everything is running fine but there is a problem with MySQL service. I get an Symfony error:
"An exception occurred in driver: could not find driver"
as well as PMA error when I try to login to DB:
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed:
Name does not resolve
Any idea how could I make it work?
docker-compose.yml:
version: '3'
services:
apache:
build: .docker/apache
container_name: sf4_apache
ports:
- 80:80
volumes:
- .docker/config/vhosts:/etc/apache2/sites-enabled
- .:/home/wwwroot/sf4
depends_on:
- php
mysql:
image: mysql
container_name: sf4_mysql
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sf4
MYSQL_USER: sf4
MYSQL_PASSWORD: sf4
php:
build: .docker/php
container_name: sf4_php
volumes:
- .:/home/wwwroot/sf4
environment:
- maildev_host=sf4_maildev
depends_on:
- maildev
- mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: sf4_phpmyadmin
ports:
- 8080:80
links:
- mysql
maildev:
image: djfarrelly/maildev
container_name: sf4_maildev
ports:
- 8001:80
Also I opened the mysql logs and I see this:
2019-04-07T12:00:30.943414Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.15' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
Maybe the port is wrong and that's why I can't connect?
For phpmyadmin service, i think you should set the PMA_HOST and PMA_PORT environment variables like this:
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: sf4_phpmyadmin
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- 8080:80
links:
- mysql
Your mysql container should have the command instruction at the start to set the authentication plugin (there is an issue with the connectors with mysql 8), more details here
mysql:
image: mysql
container_name: sf4_mysql
command: "--default-authentication-plugin=mysql_native_password"
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sf4
MYSQL_USER: sf4
MYSQL_PASSWORD: sf4
in your Symfony app, the connection string is located in .env file, and it should have the following format :
DATABASE_URL=mysql://mysql_user:mysql_user_password#mysql_host:mysql_port/db_name
mysql_user: your mysql user (ex: root)
mysql_user_password: the user's password (ex: root)
mysql_host: is should contain your mysql container service name
located in your docker-compose.yml file (mysql in this case)
mysql_port: mysql container internal port (3306, in this case)
db_name: the database you want to connect to.
the DATABASE_URL can look like this :
DATABASE_URL=mysql://root:root#mysql:3306/sf4
stop your containers after these changes and start them up again.
Hope this will help.
You have to expose the mysql port 3306:
mysql:
image: mysql
container_name: sf4_mysql
volumes:
- .docker/data/db:/var/lib/mysql
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sf4
MYSQL_USER: sf4
MYSQL_PASSWORD: sf4
networks:
- default
I think you're having trouble linking the containers. I suggest that you use a custom network instead of linking. That all containers can see each other