本地docker-compose创建的加入了同一个虚拟网络的容器,在宿主机里怎么访问?


Mac系统
Docker最新版

创建了虚拟网络同时让所有容器加入这个网络了
docker-compose.yml:
version: '2'

networks:
bigdata:
external: true

services:
zookeeper:
image: 'bitnami/zookeeper:latest'
container_name: zookeeper
ports:
  - '2181:2181'
volumes:
  - 'zookeeper_data:/bitnami'
environment:
  - ALLOW_ANONYMOUS_LOGIN=yes
networks:
  - bigdata

kafka:
image: 'bitnami/kafka:latest'
container_name: kafka
ports:
  - '9092:9092'
volumes:
  - 'kafka_data:/bitnami'
environment:
  - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
  - ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
  - zookeeper
networks:
 - bigdata

volumes:
zookeeper_data:
driver: local
kafka_data:
driver: local


network:
docker network ls
NETWORK ID          NAME                            DRIVER              SCOPE
3f42779d21d7        bigdata                         bridge              local
ef0460d55e09        bitnami-docker-kafka_app-tier   bridge              local
6ea970999f4c        bitnami-docker-kafka_default    bridge              local
f9360b4d90f6        bridge                          bridge              local
0781a86f793a        docker-flink_default            bridge              local
283b7b0c6c88        docker-kafka_default            bridge              local
af00a003a35a        docker_st_default               bridge              local
cb1d703af0fe        host                            host                local
36d1001923a9        kafka-docker_default            bridge              local
8ac8840c1467        none                            null                local


但是在本地起的服务里面,不管是用localhost:9092还是用本机ip:9092都会提示 UnknownHostException,
而且报错里面还是容器的id
java.net.UnknownHostException: 3b94186a829d
at java.net.InetAddress.getAllByName0(InetAddress.java:1281)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:104)


有没大佬知道为啥的?
已邀请:

要回复问题请先登录注册