首页 > 解决方案 > 如何在 Host 模式下使用服务名访问容器?

问题描述

version: "3.3"
services:
  test1:
    container_name: test1
    image: nginx
    network_mode: host
    restart: always
  test2:
    container_name: test2
    image: nginx
    restart: always

如果我想从 访问test1服务test2,如何test1直接通过 ping访问服务test1

test1 服务设置为主机模式,不会进行网络隔离。除了使用 IP 直接访问外,如何通过服务名称test1从容器内访问?test2test1

标签: dockerdocker-compose

解决方案


推荐阅读