1

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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.