且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laradock不适用于mysql

更新时间:2023-11-22 13:42:04

使用Laradock时,您需要考虑将容器视为一个共享网络中的独立服务器/计算机。下图的每个矩形代表一个服务器,该服务器具有自己的IP地址,自己的Linux系统等。因此,要从另一个容器连接到MySQL,您需要知道该容器的IP地址或主机名。

when you're using Laradock, you need to think about containers as if they were separate servers/computers within one shared network. Each rectangle at the picture below represents one server which has it's own IP address, own Linux system etc. Therefore to connect to MySQL from another container, you need to know an IP address or hostname of this container.

幸运的是,Laradock在幕后提供了一些魔术来缓解这种情况,您可以使用MySQL主机名代替在配置中提供IP地址。如果要启用Redis,只需要做的是,使用docker-compose启动Redis,并在Laravel配置中提供Redis主机名。

Luckily Laradock provides a little bit of magic under the hood to ease this, and you can use MySQL hostname instead of providing an IP address in your config. If you want to enable Redis, all you have to do is, start Redis with docker-compose up and provide Redis hostname in Laravel config.

如果要进行故障排除, docker-compose ps是检查正在发生的事情的***方法。其余的是对多容器概念的理解。

If it comes to troubleshooting, docker-compose ps is the best way to check what is going on. The rest is an understanding of a multi-container concept.

请注意,如果不暴露docker-compose.yml中的容器端口,就无法从主机PC连接到容器。 。容器IP对主机不可见,因为它们属于虚拟网络,而不是计算机所连接的真实IP。默认端口已在docker-compose.yml中公开,因此您可以访问IP 127.0.0.1和端口3306上的数据库,与Nginx在端口80上相同,依此类推。

Beware you can't connect to your containers from your host PC without exposing containers port in docker-compose.yml. Containers IPs are not visible for a host, as they belong to a virtual network, not the real one where your computer is connected. Default ports are already exposed in docker-compose.yml so you can access DB at IP 127.0.0.1 and port 3306, same with Nginx at port 80 and so on.

希望现在可以更清楚了:)

Hope this is a bit more clear now :)