[Docker]: Connecting PHPMyAdmin to MySQL doesnt work([Docker]:将 PHPMyAdmin 连接到 MySQL 不起作用)
问题描述
我正在尝试将 PHPMyAdmin-Container 连接到 MySQL-Container 以查看数据库.
I'm trying to connect a PHPMyAdmin-Container to a MySQL-Container to view the databases.
我已经通过 $ docker run --name databaseContainer -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
和 PHPMyAdmin-Container 通过 $ docker run --name myadmin -d --link databaseContainer:mysql -p 8080:8080 phpmyadmin/phpmyadmin
and the PHPMyAdmin-Container via $ docker run --name myadmin -d --link databaseContainer:mysql -p 8080:8080 phpmyadmin/phpmyadmin
尝试登录 PHPMyAdmin 时,我得到:mysqli_real_connect(): php_network_getaddresses: getaddrinfo 失败: 名称无法解析
When trying to login on PHPMyAdmin, I get: mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve
和
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve
顺便说一句,我还启动了一个 wordpress 容器并将其链接到 mysql,它可以工作...
By the way, I have also started a wordpress container and also linked it to mysql, there it works...
推荐答案
不要一一开始,而是使用 docker-compose
.
Instead of starting them one by one, use docker-compose
.
创建一个 docker-compose.yml 文件
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"
然后在 docker-compose.yml
文件所在的同一文件夹中使用 docker-compose up
启动它.使用浏览器访问 PHPmyadmin 并使用db"作为数据库的主机名,因为这是 docker-compose.yml
文件中的服务名称,因此可以使用 dockers 内部 DNS 服务进行解析到 docker-container 的实际 ip.所有链接都是自动为您设置的.
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.
这要简单得多 - docker run 使事情变得过于复杂并且对这些事情不实用 - 从不.
That's much simpler - docker run overcomplicates things and is not practical for those things - never.
提示:如果您的机器上未安装 docker-compose,请使用此官方文档 https 进行安装://docs.docker.com/compose/install/(超出范围)
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)
这篇关于[Docker]:将 PHPMyAdmin 连接到 MySQL 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:[Docker]:将 PHPMyAdmin 连接到 MySQL 不起作用


基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01