phpipam docker cannot connect to database - mysql

This is the configuration for my docker container. I am getting the following error: Could not connect to database! SQLSTATE[HY000] [1045] Access denied for user 'root'#'172.18.0.4' (using password: YES)
# WARNING: Replace the example passwords with secure secrets.
# WARNING: 'my_secret_phpipam_pass' and 'my_secret_mysql_root_pass'
version: '3'
services:
phpipam-web:
image: phpipam/phpipam-www:latest
ports:
- "80:80"
environment:
- TZ=Europe/London
- IPAM_DATABASE_HOST=phpipam-mariadb
- IPAM_DATABASE_PASS=my_secret_phpipam_pass
- IPAM_DATABASE_WEBHOST=%
restart: unless-stopped
volumes:
- phpipam-logo:/phpipam/css/images/logo
depends_on:
- phpipam-mariadb
phpipam-cron:
image: phpipam/phpipam-cron:latest
environment:
- TZ=Europe/London
- IPAM_DATABASE_HOST=phpipam-mariadb
- IPAM_DATABASE_PASS=my_secret_phpipam_pass
- SCAN_INTERVAL=1h
restart: unless-stopped
depends_on:
- phpipam-mariadb
phpipam-mariadb:
image: mariadb:latest
environment:
- MYSQL_ROOT_PASSWORD=my_secret_mysql_root_pass
restart: unless-stopped
volumes:
- phpipam-db-data:/var/lib/mysql
volumes:
phpipam-db-data:
phpipam-logo:
I have tried logging into the docker container directly and was unable to access mysql through it. This did not work, so I tried using the mysqladmin within the docker container to access it but that did not work either.

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

Docker / MySQL - Doctrine Migration - Access Database outside container

Hello :) here is my docker compose :
version: "3.8"
services:
web-server:
build: .
volumes:
- ./:/var/www/html/
ports:
- "8000:80"
links:
- "db:db"
db:
image: mysql:5.6
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8001:80"
links:
- "db:db"
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
As you can see, when i go to phpmyadmin with http://localhost:8001/ i have :
PhpMyAdmin Dashboard
Doctrine Migation is installed in my project, so when i try :
./vendor/bin/doctrine-migrations status
Errors are :
In AbstractMySQLDriver.php line 112:
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
In Exception.php line 18:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
In PDOConnection.php line 39:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
In PDOConnection.php line 39:
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
Connexion in my env file is :
BDD = pdo-mysql://root:root#db:3306/playlist_maker_multi
I expose port 3306 on my docker-compose so i don't understand why outside my container i can't access to my Database ?
Thanks everybody, if you have explanations.
Have a nice day.
Camille
Could you try running it with this config
I renamed the db service to mysql, explicitly added a network and made your php service depend on mysql, so it will restart untill it establishes a connection, just in case the php container starts running before the mysql container
version: "3.8"
services:
web-server:
build: .
volumes:
- ./:/var/www/html/
ports:
- "8000:80"
links:
- "mysql:db"
mysql:
image: mysql:5.6
container_name: db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
networks:
- net
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8001:80"
links:
- "mysql:db"
depends_on:
- mysql
restart: on-failure
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
networks:
- net
networks:
net:
driver: bridge
For applications running on your host machine but outside of your Docker network (i.e. not containerised) that need to connect to a container, you can use localhost instead of db, as the DNS name db is only valid inside the Docker Compose network.
With:
mysql:
image: mysql:5.6
container_name: db
ports:
- "3306:3306"
you are creating a path from locahost:3306 (or MACHINEIP:3306 if on another machine) to the service on mysql:3306 inside the network.
#clarj, do you mean like that ?
version: "3.8"
services:
web-server:
build: .
volumes:
- ./:/var/www/html/
ports:
- "8000:80"
links:
- "localhost:db"
mysql:
image: mysql:5.7
container_name: db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8001:80"
links:
- "localhost:db"
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root

How to connect phpmyadmin to mySql server with docker compose

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

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

Docker Compose phpmyadmin not connecting to MySQL

I have a docker compose file which is basically trying to build a WAMP/LAMP style environment.
Basically, PHPMyAdmin can't seem to connect to MySQL. Looking through answers here, it appeared that it was an issue with legacy auth using MySQL Image 8 so I added:
command: --default-authentication-plugin=mysql_native_password
but that didn't work, so I dropped down to mysql image5.7 and the issue is still present. For some reason, I can't connect to MySQL and I get the error:
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Try again
and
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Try again
Here is a copy of my Docker Compose which I don't think is doing anything weird.
Hoping someone can clarify that for me.
version: "3.1"
services:
site:
build: .
ports :
- "80:80"
volumes:
- ./www:/var/www/html/
links:
- database
networks:
- php-network
#######################################
# PHP MY ADMIN
#######################################
phpmyadmin:
build:
context: .
dockerfile: PHPMYADMIN.Dockerfile
restart: always
links:
- database:mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- "8080:80"
environment:
- MYSQL_USERNAME=admin
- MYSQL_PASSWORD=root
networks:
- php-network
#######################################
# MySQL server
#######################################
database:
image: mysql:5.7.25
ports:
- "3306:3306"
container_name: db-mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test_db
- MYSQL_USER=admin
- MYSQL_PASSWORD=root
networks:
- php-network
networks:
php-network:
driver: bridge
I also saw mention of a "depends on" flag which I tried too but that also failed to allow me to connect. I have had the same error throughout.
It's about the container name.
database:
image: mysql:5.7.25
ports:
- "3306:3306"
- **container_name: db-mysql**
and in your phpcontainer:
phpmyadmin:
build:
context: .
dockerfile: PHPMYADMIN.Dockerfile
restart: always
links:
- database:mysql
environment:
**PMA_HOST: mysql**
PMA_PORT: 3306
you define host as mysql, which in docker network will be unrecognizable.
try switching PMA_HOST to db-mysql.
Sorry for bad formatting.
Also use docker ps to see docker container names and to figure out which hosts do you need to connect.
I've got this working now with the following:
version: "3.1"
services:
www:
build: .
ports:
- "8081:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
#######################################
# MySQL server
#######################################
db:
image: mysql:5.7.25
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
#######################################
# PHP MY ADMIN
#######################################
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8080:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
According to your phpmyadmin service configuration, you are trying to reach mysql container by mysql address:
environment:
PMA_HOST: mysql
PMA_PORT: 3306
But container with mysql server is accessible by database or db-mysql addresses.
So, you need to change phpmyadmin service configuration to:
environment:
PMA_HOST: database
PMA_PORT: 3306