从 docker 容器连接到外部主机

Conection to external host from docker container

我的本地环境与具有 BDD 的计算机连接。当我 ping 这台机器的 IP 时,我有一个响应。

当我用 docker compose 启动我的容器时,这个容器与这台机器没有连接。如果我用 docker exec -it my-container sh 进入容器并且我 ping DBB 机器我没有反应。

我在 Windows 10 年安装了 docker,我的 Docker Compose 文件如下所示:

version: '3.1'

services:
  tomcat:
    image: 'tomcat:7.0.91-jre8-alpine'
    restart: always
    volumes:
        - ./warfiles:/home
        - ./conf:/usr/local/tomcat/conf/Catalina/localhost 
        - ./context.xml:/usr/local/tomcat/conf/context.xml
        - ./ik-report-config:/ik-report-conf
        - ./lib/postgresql-9.3-1102-jdbc4.jar:/usr/local/tomcat/lib/postgresql-9.3-1102-jdbc4.jar
    ports:
        - 8070:8080
        - 8000:8000
    environment:
     - REPORT_ENGINE_HOME=/ik-report-conf

非常感谢您的帮助。

您可能应该使用 network_mode: host

来自Docker Network Guide

host: For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking directly.

我必须使用的是network_mode: bridge