Unable to connect phpmyadmin to database using docker compose
Solution 1
Interestng enough, I have your compose-file running and phpmyadmin is accessible from host.
Had to change port 8000 to 8004 though (port 8000 is occupied on my host).
In case your db-container does not start fast enough for phpmyadmin to connect, I suggest adding depends_on into phpmyadmin service. Makes sure db starts before phpmyadmin.
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_PORT: 3306
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: toor
ports:
- "8004:80"
restart: always
depends_on:
- db
networks:
- web
Please show logs from docker-compose up
if problem persists.
Solution 2
Now you need to add command to mysql service for connecting to phpmyadmin.
command: --default-authentication-plugin=mysql_native_password
version: "2"
services:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: drupal
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- /var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
PMA_HOST: db
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
Related videos on Youtube
Syed Aqeel
I’m a senior software engineer with 4+ years experience working professionally.Presently I’m looking for my next role in a diverse and inclusive team. As a web developer, I have great experience in PHP, MVC(Laravel), OOP, PHP Modelling, and also experienced in client-side technologies like Javascript, ReactJS, AngularJS. I have also great skills in Database management, RDBMS Development and worked on MySQL, Oracle DB, SQLite, and IndexedDB. I’m learning about things such as MongoDB, NoSQL, Data Science, Data Security and machine learning and also SEO(Search Engine Optimization) Development, and have worked a lot with performance analysis, multiple databases (MySQL, etc), and service-based architectures. I have recently worked on the development of E-Commerce website and served as UX designer and Code Optimizer. I have Worked in different sort of companies like small and big(not very).Worked on many projects based on Restful API, the task understanding, and working as a part of the team is my great ability. If any of the above sounds like someone you’d be interested in interviewing & hiring, you can try my skills, although, it is a little more focused on my work as a front-end engineer.
Updated on June 04, 2022Comments
-
Syed Aqeel almost 2 years
May be this question asked few times before but I did't get a valid answer which can solve my problem.
I am trying to run phpmyadmin in docker on different container using
docker-compose
but It always through the following error:#2002 - Connection refused — The server is not responding (or the local server's socket is not correctly configured).
My docker compose file contains the following code:
version: "2" services: web: build: . ports: - "80:80" networks: - web volumes: - .:/code restart: always db: image: "mysql:5" volumes: - ./mysql:/etc/mysql/conf.d environment: MYSQL_ROOT_PASSWORD: toor MYSQL_DATABASE: phpapp networks: - web restart: always phpmyadmin: image: phpmyadmin/phpmyadmin environment: PMA_PORT: 3306 PMA_HOST: db PMA_USER: root PMA_PASSWORD: toor ports: - "8000:80" restart: always networks: - web networks: web: driver: bridge
In
web
container I am trying to connect with database and it works fine, but the problem occur withphpmyadmin
connectionAny help would be appreciated. :)
-
Syed Aqeel about 6 yearsThis was the actual problem. Thanks