简体   繁体   中英

docker-compose networking - hostname not resolving

I have the following docker-compose file. I am trying to access the service running in the container, from the host.

But the hostname never resolves.

version: '2'
networks: 
  mynet:
    driver: bridge
services:


  grpcserver:
    image: test/image
    volumes:
      - ./:/var/local/git
    ports:
      - 50051:50051
    stdin_open: true
    tty: true
    hostname: grpcserver
    networks: 
      - mynet
    entrypoint: bash ../var/local/git/service/start.sh

When I exec to the container I can telnet grpcserver 50051 to the running service using the hostname successfully. But from the host, I cannot.

Version

docker-compose version 1.16.1, build 6d1ac21

Docker containers are not resolved using their name on the host. They can only be resolved inside other containers. The name would be dependent on whether you are trying to connect from another service in same compose/network or a different one.

If you need your containers to be discoverable from host you need to use a tool like dnsmasq. See the answer below on more details on how to do such a setup

Access to container by his hostname from host-mascine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM