-1

I am trying to make a quick connection setup using the fallowing setup

Copy & Paste to recreate the issue

docker rm -f mariadb && docker run --detach --name mariadb --env MARIADB_USER=user --env MARIADB_PASSWORD=secret --env MARIADB_ROOT_PASSWORD=secret -p 3306:3306 mariadb:latest

docker rm -f phpmyadd && docker run --name phpmyadd -d -e PMA_HOST=host -e PMA_PORT=3306 -p 8080:80 phpmyadmin

docker exec -it mariadb  bash

I can login in to mariadb container and access mariadb with

mysql -uroot -psecret

enter image description here

I can also access phpmyadmin container at http://localhost:8080

However when i try to login to mariadb through phpmyadmin i get the fallowing:

enter image description here

It shows that the port is exposed but I can not access it with telnet.. enter image description here

Any idea what is missing here?

DevWL
  • 17,345
  • 6
  • 90
  • 86
  • The two containers need to be on the same `docker run --network`, and then their `docker run --name` will be usable as hostnames. See for example [How to communicate between Docker containers via "hostname"](https://stackoverflow.com/questions/30545023/how-to-communicate-between-docker-containers-via-hostname) for examples. – David Maze Jul 15 '22 at 10:24

1 Answers1

0

For 2 containers to be able to talk to each other, you would have to setup a docker-compose instead. Something like this should work

version: '3.8'

volumes:
  mariadb:
    driver: local

services:
  mariadb:
    image: mariadb:10.6
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: YOUR_ROOT_PASSWORD_HERE
      MYSQL_USER:  YOUR_MYSQL_USER_HERE 
      MYSQL_PASSWORD: YOUR_USER_PW_HERE
    ports:
      - "40000:3306"
    volumes:
      - mariadb:/var/lib/mysql
              
  phpmyadmin:
    image: phpmyadmin
    restart: always
    ports:
      - "40001:80"
    environment:
      - PMA_HOST=mariadb
      - PMA_PORT=3306 

And you would start everything using docker-compose up

David Maze
  • 130,717
  • 29
  • 175
  • 215
g.p
  • 312
  • 1
  • 5
  • The above docker-compose return connection Error: 'mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'172.21.0.3' (using password: YES)'. Passwords and user name were configured. – DevWL Jul 15 '22 at 10:53