Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[Docker]: Connecting PHPMyAdmin to MySQL doesnt work

I'm trying to connect a PHPMyAdmin-Container to a MySQL-Container to view the databases.

I have started the MySQL container via $ docker run --name databaseContainer -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql

and the PHPMyAdmin-Container via $ docker run --name myadmin -d --link databaseContainer:mysql -p 8080:8080 phpmyadmin/phpmyadmin

When trying to login on PHPMyAdmin, I get: mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve

and

mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve

By the way, I have also started a wordpress container and also linked it to mysql, there it works...

like image 468
Pascal Avatar asked Aug 20 '16 12:08

Pascal


People also ask

How do I run phpMyAdmin and MySQL Docker?

You only need to open your favourite browser and type the following url: http://localhost:8081/ so your instance of phpMyAdmin will show up. To access, type root as username and the password you established in the step one when running the mysql container (if you followed the tutorial the password is mypass123).

Can I use MySQL with Docker?

MySQL is one of the most popular SQL-compatible relational databases. Running MySQL inside a Docker container lets you separate your database from your code. You can also use a container orchestrator like Kubernetes to scale MySQL independently of your API server instance.

How do I run both Apache and MySQL from Dockerfile?

You would add that Bash script to your Docker build process, and then setup CMD to run that script, instead of starting just MySQL or just Apache. The Docker documentation has some examples here for how to setup a single container with multiple services.


Video Answer


1 Answers

Instead of starting them one by one, use docker-compose.

Create a docker-compose.yml file

version: '2'
services:
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: my-secret-pw
    ports:
      # just if you also want to access it directly from you host
      # node neede for phpmyadmin
      - "3306:3306"
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    depends_on:
      - db
    ports:
      - "8080:8080"

Then start it using docker-compose up in the same folder your docker-compose.yml file is located. Access PHPmyadmin using the browser and use 'db' as the hostname of your database, since that is the name of the service in the docker-compose.yml file and therefore can be resolved using dockers internal DNS service to the actual ip of the docker-container. All the links are setup for you automatically.

That's much simpler - docker run overcomplicates things and is not practical for those things - never.

Hint: if docker-compose is not installed on your machine, install it using this official docs https://docs.docker.com/compose/install/ (out of scope)

like image 185
Eugen Mayer Avatar answered Sep 20 '22 14:09

Eugen Mayer