Docker: Can't login in my mariadb using phpmyadmin - mysql

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

Related

Cannot resolve hostname in docker desktop windows

I have setup docker-compose to run phpmyadmin and mysql. Here is my docker-compose.yml
version: "3.9"
networks:
local_web_network:
driver: bridge
volumes:
mysql_data:
driver: local
services:
mysql:
image: mysql:8.0
container_name: local_mysql
restart: always
tty: true
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_DATABASE: local_master
MYSQL_ROOT_PASSWORD: secret
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
volumes:
- mysql_data:/var/lib/mysql
networks:
- local_web_network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: local_phpmyadmin
restart: always
tty: true
ports:
- "8083:80"
environment:
PMA_HOST: local_mysql
PMA_ABSOLUTE_URI: http://db.test
MYSQL_ROOT_PASSWORD: secret
networks:
- local_web_network
extra_hosts:
- 'db.test:127.0.0.1'
I have configured the windows hosts file with the below settings
127.0.0.1 db.test
I have successfully run the docker containers without any errors. I have tried accessing the http://127.0.0.1:8083 or http://db.test:8083 it works and displays the phpmyadmin login page.
But the problem here is, i am unable to access the page without specifying the port i.e http://db.test. How do i get this working without specifying the port?

mysql database name and credentials inside docker container not updating

I have a LAMP stack with laravel setup in docker-compose containers,everything seems to be working fine so far. I initially had a test database with the name of homestead setup in docker-compose.yml that was just there for testing now i want to change it to something more meaningful like my project name. let me show you my docker-compose.yml
version: '3'
networks:
laravel:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: nginx
ports:
- 80:80
volumes:
- ./src:/var/www/html:delegated
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- 3306:3306
environment:
MYSQL_DATABASE: alis
MYSQL_USER: alis
MYSQL_PASSWORD: pass
MYSQL_ROOT_PASSWORD: pass
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: php.dockerfile
container_name: php
volumes:
- ./src:/var/www/html:delegated
networks:
- laravel
composer:
build:
context: .
dockerfile: composer.dockerfile
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
user: laravel
entrypoint: ['composer', '--ignore-platform-reqs']
networks:
- laravel
npm:
image: node:latest
container_name: npm
volumes:
- ./src:/var/www/html
ports:
- 3000:3000
- 3001:3001
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html:delegated
depends_on:
- mysql
working_dir: /var/www/html
user: laravel
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
container_name: phpmyadmin
depends_on:
- mysql
ports:
- "8081:80"
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: secret
networks:
- laravel
the problem is phpmyadmin is still using the old database and credentials , it tried the following solutions
docker-compose down
docker-compose down -v
then
docker-compose up -d
this didnt work.Out of frustration even thought this is probably not the best way to do it, I removed all containers, all images and then ran
docker-compose up -d
to re-install everything from scratch to my surprise phpmyadmin still picks up the old database config.Does anyone know the reason for this behaviour?
Your phpmyadmin service tries to connect as root:secret (MYSQL_ROOT_PASSWORD) while your mysql service defines root:pass (MYSQL_ROOT_PASSWORD) as admin user.
See the available configuration here:
https://hub.docker.com/_/phpmyadmin
https://hub.docker.com/_/mysql

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 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

Access mysql db inside docker container from outside

I'm learning to use docker to make my development easier but I'm still failing access mysql.
Here is my docker-compose.yaml:
version: '3.3'
services:
# Database
db:
image: mysql:latest
ports:
- '3306:3306'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: dev1
MYSQL_USER: root
MYSQL_PASSWORD: password
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes: ['./:/var/www/html']
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: dev1
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
Wordpress is running without difficulties which means that mysql must be alright too. I'm on Linux and trying to connect database via mysql workbench. It appears that connection is also ok expect for, there is no schema and so no wordpress tables.
I tried to add also phpmyadmin into docker-compose.yaml:
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
but here I get following error after attempt to access db:
What I miss?
EDIT:
here is overview of running containers:
So i modified your docker-compose , with 2 small changes , and i dont have a issue .
I created a user for wordpress ( userdev1 ) in mysql .
The root is already here and can have some restrictions for remote access .
Via phpmyadmin i can login with userdev1 or root
You want a network access with the root account you must set this variable
MYSQL_ROOT_HOST .
You can find more information on this page (
https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/docker-mysql-more-topics.html#docker_var_mysql-root-host )
version: '3.3'
services:
# Database
db:
image: mysql:5.7
ports:
- '3306:3306'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password4root
MYSQL_DATABASE: dev1
MYSQL_USER: userdev1
MYSQL_PASSWORD: password4dev1
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes: ['./:/var/www/html']
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: userdev1
WORDPRESS_DB_PASSWORD: password4dev1
WORDPRESS_DB_NAME: dev1
networks:
- wpsite
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
** UPDATED **
With the very last version of mysql docker image ( aka mysql 8.0 ),
you must change the default-authentification to mysql_native_password to be comptatible with legacy mysql client
source :
https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password