Docker cannot ping local network machines by hostname











up vote
0
down vote

favorite












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 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?
    – user10067412
    Nov 12 at 23:37

















up vote
0
down vote

favorite












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 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?
    – user10067412
    Nov 12 at 23:37















up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 at 23:45

























asked Nov 11 at 3:36









user10067412

988




988












  • 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 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?
    – user10067412
    Nov 12 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 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?
    – user10067412
    Nov 12 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 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 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?
– user10067412
Nov 12 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?
– user10067412
Nov 12 at 23:37














2 Answers
2






active

oldest

votes

















up vote
0
down vote













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




























    up vote
    0
    down vote













    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.
      – user10067412
      Nov 12 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',
    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








    up vote
    0
    down vote













    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

























      up vote
      0
      down vote













      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























        up vote
        0
        down vote










        up vote
        0
        down vote









        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 at 13:05









        Ivonet

        1,150518




        1,150518
























            up vote
            0
            down vote













            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.
              – user10067412
              Nov 12 at 23:39















            up vote
            0
            down vote













            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.
              – user10067412
              Nov 12 at 23:39













            up vote
            0
            down vote










            up vote
            0
            down vote









            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 at 5:35









            Dileep Jayasundara

            534




            534












            • 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.
              – user10067412
              Nov 12 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.
              – user10067412
              Nov 12 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.
            – user10067412
            Nov 12 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.
            – user10067412
            Nov 12 at 23:39


















             

            draft saved


            draft discarded



















































             


            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

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation