Docker cannot ping local network machines by hostname










0















I am transitioning my webserver and db into docker containers and using docker-compose to fire them up but encountering an issue. My container starts successfully, however, I have functions that pings other servers by hostname in my private network and that doesn't seem to work anymore when inside a docker container. For example:



ping other_hostname (cannot reach hostname inside container)


when I'm outside the container and ping other_hostname it works fine.



I did notice that when inside the container if I qualify the hostname like this:



ping other_hostname.home.com (this works inside the container)


Is there a way to ping by hostname when inside the container?



mount:



...

/dev/sdb3 on /etc/resolv.conf type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/resolv.conf)
/dev/sdb3 on /etc/hostname type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hostname)
/dev/sdb3 on /etc/hosts type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hosts)

...


resolve.conf:



~ $ cat /etc/resolv.conf
search mydomain.com
nameserver 127.0.0.11
options ndots:0









share|improve this question
























  • If I followed your example, check what is in /etc/resolv.conf in both the host and the container. Also, in the container check mount to see what has been added.

    – KevinO
    Nov 11 '18 at 3:56











  • @KevinO So i see the mounts in my docker container, however, my resolv.conf in my container does not match my host. I only see nameserver 127.0.0.11 in my container. Is there a way to be able to use my hosts resolve.conf file?

    – honeybadger_execute
    Nov 12 '18 at 23:37
















0















I am transitioning my webserver and db into docker containers and using docker-compose to fire them up but encountering an issue. My container starts successfully, however, I have functions that pings other servers by hostname in my private network and that doesn't seem to work anymore when inside a docker container. For example:



ping other_hostname (cannot reach hostname inside container)


when I'm outside the container and ping other_hostname it works fine.



I did notice that when inside the container if I qualify the hostname like this:



ping other_hostname.home.com (this works inside the container)


Is there a way to ping by hostname when inside the container?



mount:



...

/dev/sdb3 on /etc/resolv.conf type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/resolv.conf)
/dev/sdb3 on /etc/hostname type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hostname)
/dev/sdb3 on /etc/hosts type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hosts)

...


resolve.conf:



~ $ cat /etc/resolv.conf
search mydomain.com
nameserver 127.0.0.11
options ndots:0









share|improve this question
























  • If I followed your example, check what is in /etc/resolv.conf in both the host and the container. Also, in the container check mount to see what has been added.

    – KevinO
    Nov 11 '18 at 3:56











  • @KevinO So i see the mounts in my docker container, however, my resolv.conf in my container does not match my host. I only see nameserver 127.0.0.11 in my container. Is there a way to be able to use my hosts resolve.conf file?

    – honeybadger_execute
    Nov 12 '18 at 23:37














0












0








0








I am transitioning my webserver and db into docker containers and using docker-compose to fire them up but encountering an issue. My container starts successfully, however, I have functions that pings other servers by hostname in my private network and that doesn't seem to work anymore when inside a docker container. For example:



ping other_hostname (cannot reach hostname inside container)


when I'm outside the container and ping other_hostname it works fine.



I did notice that when inside the container if I qualify the hostname like this:



ping other_hostname.home.com (this works inside the container)


Is there a way to ping by hostname when inside the container?



mount:



...

/dev/sdb3 on /etc/resolv.conf type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/resolv.conf)
/dev/sdb3 on /etc/hostname type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hostname)
/dev/sdb3 on /etc/hosts type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hosts)

...


resolve.conf:



~ $ cat /etc/resolv.conf
search mydomain.com
nameserver 127.0.0.11
options ndots:0









share|improve this question
















I am transitioning my webserver and db into docker containers and using docker-compose to fire them up but encountering an issue. My container starts successfully, however, I have functions that pings other servers by hostname in my private network and that doesn't seem to work anymore when inside a docker container. For example:



ping other_hostname (cannot reach hostname inside container)


when I'm outside the container and ping other_hostname it works fine.



I did notice that when inside the container if I qualify the hostname like this:



ping other_hostname.home.com (this works inside the container)


Is there a way to ping by hostname when inside the container?



mount:



...

/dev/sdb3 on /etc/resolv.conf type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/resolv.conf)
/dev/sdb3 on /etc/hostname type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hostname)
/dev/sdb3 on /etc/hosts type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var/lib/docker/containers/13cfa734b33cda82a5e487d5a2a4b9aad2fdefaf844b49a4f92c99c4fd2089b8/hosts)

...


resolve.conf:



~ $ cat /etc/resolv.conf
search mydomain.com
nameserver 127.0.0.11
options ndots:0






docker docker-compose ping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 23:45







honeybadger_execute

















asked Nov 11 '18 at 3:36









honeybadger_executehoneybadger_execute

1148




1148












  • If I followed your example, check what is in /etc/resolv.conf in both the host and the container. Also, in the container check mount to see what has been added.

    – KevinO
    Nov 11 '18 at 3:56











  • @KevinO So i see the mounts in my docker container, however, my resolv.conf in my container does not match my host. I only see nameserver 127.0.0.11 in my container. Is there a way to be able to use my hosts resolve.conf file?

    – honeybadger_execute
    Nov 12 '18 at 23:37


















  • If I followed your example, check what is in /etc/resolv.conf in both the host and the container. Also, in the container check mount to see what has been added.

    – KevinO
    Nov 11 '18 at 3:56











  • @KevinO So i see the mounts in my docker container, however, my resolv.conf in my container does not match my host. I only see nameserver 127.0.0.11 in my container. Is there a way to be able to use my hosts resolve.conf file?

    – honeybadger_execute
    Nov 12 '18 at 23:37

















If I followed your example, check what is in /etc/resolv.conf in both the host and the container. Also, in the container check mount to see what has been added.

– KevinO
Nov 11 '18 at 3:56





If I followed your example, check what is in /etc/resolv.conf in both the host and the container. Also, in the container check mount to see what has been added.

– KevinO
Nov 11 '18 at 3:56













@KevinO So i see the mounts in my docker container, however, my resolv.conf in my container does not match my host. I only see nameserver 127.0.0.11 in my container. Is there a way to be able to use my hosts resolve.conf file?

– honeybadger_execute
Nov 12 '18 at 23:37






@KevinO So i see the mounts in my docker container, however, my resolv.conf in my container does not match my host. I only see nameserver 127.0.0.11 in my container. Is there a way to be able to use my hosts resolve.conf file?

– honeybadger_execute
Nov 12 '18 at 23:37













2 Answers
2






active

oldest

votes


















0














If you have a docker-compose.yml example like below you can access the different services by their name. Docker will treat them as their dns name.



So in the case below it would be mysql-service and gogs-service



version: '3'

services:
mysql-service:
image: mysql
volumes:
- ./setup:/docker-entrypoint-initdb.d
- mysql-data:/var/lib/mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=secret

gogs-service:
image: gogs
volumes:
- gogs-data:/data
links:
- mysql:mysql
ports:
- "10022:22"
- "10000:3000"

volumes:
mysql-data:
driver: local
gogs-data:
driver: local


hope it helps :-)






share|improve this answer






























    0














    Add your local dns server to docker container /etc/resolv.conf file as



    nameserver dns_server_ip


    then restart docker container.






    share|improve this answer























    • How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

      – honeybadger_execute
      Nov 12 '18 at 23:39










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245625%2fdocker-cannot-ping-local-network-machines-by-hostname%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you have a docker-compose.yml example like below you can access the different services by their name. Docker will treat them as their dns name.



    So in the case below it would be mysql-service and gogs-service



    version: '3'

    services:
    mysql-service:
    image: mysql
    volumes:
    - ./setup:/docker-entrypoint-initdb.d
    - mysql-data:/var/lib/mysql
    ports:
    - "3306:3306"
    environment:
    - MYSQL_ROOT_PASSWORD=secret

    gogs-service:
    image: gogs
    volumes:
    - gogs-data:/data
    links:
    - mysql:mysql
    ports:
    - "10022:22"
    - "10000:3000"

    volumes:
    mysql-data:
    driver: local
    gogs-data:
    driver: local


    hope it helps :-)






    share|improve this answer



























      0














      If you have a docker-compose.yml example like below you can access the different services by their name. Docker will treat them as their dns name.



      So in the case below it would be mysql-service and gogs-service



      version: '3'

      services:
      mysql-service:
      image: mysql
      volumes:
      - ./setup:/docker-entrypoint-initdb.d
      - mysql-data:/var/lib/mysql
      ports:
      - "3306:3306"
      environment:
      - MYSQL_ROOT_PASSWORD=secret

      gogs-service:
      image: gogs
      volumes:
      - gogs-data:/data
      links:
      - mysql:mysql
      ports:
      - "10022:22"
      - "10000:3000"

      volumes:
      mysql-data:
      driver: local
      gogs-data:
      driver: local


      hope it helps :-)






      share|improve this answer

























        0












        0








        0







        If you have a docker-compose.yml example like below you can access the different services by their name. Docker will treat them as their dns name.



        So in the case below it would be mysql-service and gogs-service



        version: '3'

        services:
        mysql-service:
        image: mysql
        volumes:
        - ./setup:/docker-entrypoint-initdb.d
        - mysql-data:/var/lib/mysql
        ports:
        - "3306:3306"
        environment:
        - MYSQL_ROOT_PASSWORD=secret

        gogs-service:
        image: gogs
        volumes:
        - gogs-data:/data
        links:
        - mysql:mysql
        ports:
        - "10022:22"
        - "10000:3000"

        volumes:
        mysql-data:
        driver: local
        gogs-data:
        driver: local


        hope it helps :-)






        share|improve this answer













        If you have a docker-compose.yml example like below you can access the different services by their name. Docker will treat them as their dns name.



        So in the case below it would be mysql-service and gogs-service



        version: '3'

        services:
        mysql-service:
        image: mysql
        volumes:
        - ./setup:/docker-entrypoint-initdb.d
        - mysql-data:/var/lib/mysql
        ports:
        - "3306:3306"
        environment:
        - MYSQL_ROOT_PASSWORD=secret

        gogs-service:
        image: gogs
        volumes:
        - gogs-data:/data
        links:
        - mysql:mysql
        ports:
        - "10022:22"
        - "10000:3000"

        volumes:
        mysql-data:
        driver: local
        gogs-data:
        driver: local


        hope it helps :-)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 '18 at 13:05









        IvonetIvonet

        1,167518




        1,167518























            0














            Add your local dns server to docker container /etc/resolv.conf file as



            nameserver dns_server_ip


            then restart docker container.






            share|improve this answer























            • How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

              – honeybadger_execute
              Nov 12 '18 at 23:39















            0














            Add your local dns server to docker container /etc/resolv.conf file as



            nameserver dns_server_ip


            then restart docker container.






            share|improve this answer























            • How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

              – honeybadger_execute
              Nov 12 '18 at 23:39













            0












            0








            0







            Add your local dns server to docker container /etc/resolv.conf file as



            nameserver dns_server_ip


            then restart docker container.






            share|improve this answer













            Add your local dns server to docker container /etc/resolv.conf file as



            nameserver dns_server_ip


            then restart docker container.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 '18 at 5:35









            Dileep JayasundaraDileep Jayasundara

            514




            514












            • How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

              – honeybadger_execute
              Nov 12 '18 at 23:39

















            • How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

              – honeybadger_execute
              Nov 12 '18 at 23:39
















            How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

            – honeybadger_execute
            Nov 12 '18 at 23:39





            How can I automate this in docker-compose? I checked my resolv.conf in my docker container but it only shows nameserver 127.0.0.11 and not the ones on my host.

            – honeybadger_execute
            Nov 12 '18 at 23:39

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245625%2fdocker-cannot-ping-local-network-machines-by-hostname%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế