无法从 docker 工具箱访问主机

Can't access host machine from docker toolbox

提问人:AEM 提问时间:10/8/2023 更新时间:10/8/2023 访问量:42

问:

我已经在 Windows Server 2016 上安装了 Docker Toolbox。我还容器化了我的Spring Boot应用程序,我的数据库在主机上作为独立应用程序运行,而不是作为容器运行。我想使用 localhost 访问数据库,无论我是在线还是离线。

docker compose.yaml

version: "3.3"
services:
  engine:
    image: myimages23.azurecr.io/myimages23:Hyperbill-Engine-3719
    container_name: Engine
    ports:
      - 8086:8003
    #network_mode: host
    # extra_hosts:
    #   - "host.docker.internal:host-gateway"
    # extra_hosts:
    #   - "dockerhost:$DOCKERHOST"

application-properties.yml

 datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:sqlserver://192.168.1.20:1433;database=my-db-test
    username: username
    password: password

这是我到目前为止尝试过的:

  1. 使用主机 ip 访问数据库并且它正在工作,但如果出现连接问题,我无法连接到数据库。
  2. 我也尝试了这个命令,但我得到了.host.docker.internal:host-gateway invalid IP address in add-host: "host-gateway"
  3. 我尝试使用而不是访问数据库,但没有工作。hostnamehostip
docker-compose windows-server docker-toolbox

评论


答: 暂无答案