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
docker docker-compose ping
add a comment |
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
docker docker-compose ping
If I followed your example, check what is in/etc/resolv.conf
in both the host and the container. Also, in the container checkmount
to see what has been added.
– KevinO
Nov 11 at 3:56
@KevinO So i see the mounts in my docker container, however, myresolv.conf
in my container does not match my host. I only seenameserver 127.0.0.11
in my container. Is there a way to be able to use my hostsresolve.conf
file?
– honeybadger_execute
Nov 12 at 23:37
add a comment |
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
docker docker-compose ping
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
docker docker-compose ping
edited Nov 12 at 23:45
asked Nov 11 at 3:36
honeybadger_execute
1098
1098
If I followed your example, check what is in/etc/resolv.conf
in both the host and the container. Also, in the container checkmount
to see what has been added.
– KevinO
Nov 11 at 3:56
@KevinO So i see the mounts in my docker container, however, myresolv.conf
in my container does not match my host. I only seenameserver 127.0.0.11
in my container. Is there a way to be able to use my hostsresolve.conf
file?
– honeybadger_execute
Nov 12 at 23:37
add a comment |
If I followed your example, check what is in/etc/resolv.conf
in both the host and the container. Also, in the container checkmount
to see what has been added.
– KevinO
Nov 11 at 3:56
@KevinO So i see the mounts in my docker container, however, myresolv.conf
in my container does not match my host. I only seenameserver 127.0.0.11
in my container. Is there a way to be able to use my hostsresolve.conf
file?
– honeybadger_execute
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?– honeybadger_execute
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?– honeybadger_execute
Nov 12 at 23:37
add a comment |
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 :-)
add a comment |
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.
How can I automate this in docker-compose? I checked myresolv.conf
in my docker container but it only showsnameserver 127.0.0.11
and not the ones on my host.
– honeybadger_execute
Nov 12 at 23:39
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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 :-)
add a comment |
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 :-)
add a comment |
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 :-)
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 :-)
answered Nov 11 at 13:05
Ivonet
1,167518
1,167518
add a comment |
add a comment |
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.
How can I automate this in docker-compose? I checked myresolv.conf
in my docker container but it only showsnameserver 127.0.0.11
and not the ones on my host.
– honeybadger_execute
Nov 12 at 23:39
add a comment |
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.
How can I automate this in docker-compose? I checked myresolv.conf
in my docker container but it only showsnameserver 127.0.0.11
and not the ones on my host.
– honeybadger_execute
Nov 12 at 23:39
add a comment |
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.
Add your local dns server to docker container /etc/resolv.conf
file as
nameserver dns_server_ip
then restart docker container.
answered Nov 12 at 5:35
Dileep Jayasundara
514
514
How can I automate this in docker-compose? I checked myresolv.conf
in my docker container but it only showsnameserver 127.0.0.11
and not the ones on my host.
– honeybadger_execute
Nov 12 at 23:39
add a comment |
How can I automate this in docker-compose? I checked myresolv.conf
in my docker container but it only showsnameserver 127.0.0.11
and not the ones on my host.
– honeybadger_execute
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.– honeybadger_execute
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.– honeybadger_execute
Nov 12 at 23:39
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
If I followed your example, check what is in
/etc/resolv.conf
in both the host and the container. Also, in the container checkmount
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 seenameserver 127.0.0.11
in my container. Is there a way to be able to use my hostsresolve.conf
file?– honeybadger_execute
Nov 12 at 23:37