MAC |从 VirtualBox 计算机上的另一个应用程序访问部署在 Docker 上的应用程序

MAC | Access application deployed on Docker from another application on VirtualBox machine

机器 - MAC bookPro Mac OSx 10.11.6

Docker - Docker 对于 mac Docker version 17.03.1-ce, build c6d412e

VirtualBox - Version 5.1.22 r115126 (Qt5.6.2)

我的 AEM (CMS) 运行 在 Virtual Box 上的图像上,使用 Vagrant + Chef 配置。我们将 IP 显式分配给盒子 - 192.168.x.x

我们已经引入了我们希望使用 Docker 部署的微服务 (Spring boot + MySQL)。 在我的本地 (MAC) 上,我成功启动了微服务,并且 运行 和两个 docker 实例(微服务,MySQL)成功相互连接。微服务公开了我需要从 Virtual box 中的 AEM 运行 调用的某些端点。这是我无法做到的,我的 virtualbox 实例无法连接到 docker 托管应用程序(docker machine 的 ip 在我的 virtualbox 中无法访问)

我使用 docker compose 让我的 docker 实例正常工作 -

这是我的docker-compose.yml

version: "3"

services:
  db:
    #build:
    #  context: ./registration-database
    image: mysql
    container_name: afs-mysql
    #network_mode: "bridge"
    # set default mysql root password, change as needed
    environment:
      MYSQL_DATABASE: afs_service
      MYSQL_ROOT_PASSWORD: root
    # Expose port 3306 to host. Not for the application but
    # handy to inspect the database from the host machine.
    ports:
      - "3309:3306" 
    restart: always

  webserver:
    container_name: afs-microservice
    #network_mode: "bridge"
    depends_on:
      - db
    links:
      - db
   # build: 
   #   context: ./registration-webserver
    image: afs-service
    # mount point for application in tomcat
    #volumes:
    #  - ./app/target/UserSignup:/usr/local/tomcat/webapps/UserSignup
    environment:
      DATABASE_HOST: db
      DATABASE_USER: root
      DATABASE_PASSWORD: root
      DATABASE_NAME: afs_service
      DATABASE_PORT: 3306
    # open ports for tomcat and remote debugging
    ports:
      - "8080:8080" 
      - "8089:8089"
    restart: always

还需要做些什么才能从 virtualbox 访问 docker 暴露的应用程序。

您可以通过连接到您 mac 的 IP 地址来访问任何 docker-for-mac 已发布的端口。

既然您提到要从虚拟机 machine 内部访问您的 Mac,您有几个选择:

  • (virtualbox 主机模式网络)- 只需在 virtualbox host-only 网络上连接到 mac 的 IP 地址。通常这将匹配 virtualbox VM 的 IP,但以 .1 结尾。例如,如果连接到仅主机网络的 virtualbox 以太网接口的 IP 为 192.168.30.100,那么您的 mac 在该仅主机网络上的 IP 几乎可以肯定是 192.168.30.1。您应该能够在 mac.
  • 上的 ifconfig 的输出中看到此 ip
  • (virtualbox NAT 模式网络)- 连接到您的 virtualbox VM 看到的网关 IP 地址。 Virtualbox 的主机模式网络会将这些连接转发到您的 mac 的 127.0.0.1
  • 连接到您的 mac 的 en0 ip 地址。这个 IP 仍然可以从你的 virtualbox VM 内部访问。