简体   繁体   English

运行docker容器时连接到本地数据库

[英]Connecting to local DB while running docker container

I am running an app from a docker container and at some point, I had Sequel Pro connected to my local DB but since reinstalling Sequel Pro, I haven't had luck connecting back to my local DB. 我正在从docker容器中运行应用程序,有时,我将Sequel Pro连接到本地数据库,但是自从重新安装Sequel Pro之后,我再也没有运回本地数据库的运气了。 Where would I find the IP/port to use for this? 我在哪里可以找到用于此目的的IP /端口? I tried connecting to 127.0.0.1 and also tried using the IP address listed in docker inspect (container name) to no avail. 我尝试连接到127.0.0.1,还尝试使用docker inspect (container name)列出的IP地址无济于事。

If you address localhost (or 127.0.0.1 ) inside your container you refer to the localhost inside the container, not the system. 如果在容器内部寻址localhost (或127.0.0.1 ),则引用容器内部的localhost ,而不是系统。

You can use docker networks . 您可以使用docker网络 If you run the container in the same network (manually adding or with a compose file) you can address like service name:port inside the network. 如果您在同一网络中运行容器(手动添加或使用撰写文件),则可以在网络内部寻址service name:port Ports does not have published outside for this (but useful if you want to rech your DB from your system). 端口尚未为此发布(如果要从系统中还原数据库,则很有用)。

A alternativ way is to run your container in network mode host . 另一种方法是在网络模式host运行容器。 In this case you run on the network interface of the docker deamon und can use localhost . 在这种情况下,您将在docker deamon的网络接口上运行,并且可以使用localhost But you lose some of your isolation. 但是您会失去一些孤立感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM