gpt4 book ai didi

mysql - 使用 docker for wordpress 进行端口转发

转载 作者:行者123 更新时间:2023-11-29 01:55:52 26 4
gpt4 key购买 nike

我是 docker 的新手。我按照这里的教程 https://www.youtube.com/watch?v=Pe6a8Jbvi9E使用 docker 创建 WordPress 站点。他正在使用以下命令解释端口转发,

docker run --link=my_mysql:mysql -p 80:80 -d wordpress

据我了解,这会将主机80端口的所有请求重定向到容器的80端口。但是这个怎么和mysql的3306端口通信呢?而且在该教程数据库详细信息中没有为 wordpress 设置任何地方,而不是从哪里获取数据库配置值?有人可以解释吗?抱歉,如果这是非常基本的问题。

最佳答案

But how this will communicate with the port 3306 of mysql?

wordpress容器将与 mysql 通信容器,因为这是链接所允许的:(参见 Linking Containers Together)

Links allow containers to discover each other and securely transfer information about one container to another container. When you set up a link, you create a conduit between a source container and a recipient container.

因此端口 3306 暴露给主机(就像 80 端口一样),但它对 wordpress 可见容器。

Docker creates a secure tunnel between the containers that doesn't need to expose any ports externally on the container; you'll note when we started the db container we did not use either the -P or -p flags.
That's a big benefit of linking: we don't need to expose the source container, here the mysql database, to the network.

Docker defines a set of environment variables for each port exposed by the source container.
Each variable has a unique prefix in the form:

<name>_PORT_<port>_<protocol>

The components in this prefix are:

  • the alias <name> specified in the --link parameter (for example, mysql)
  • the <port> number exposed
  • a <protocol> which is either TCP or UDP

关于mysql - 使用 docker for wordpress 进行端口转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29536433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com