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?
– user10067412
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
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 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?
– user10067412
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?
– 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
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.
– user10067412
Nov 12 at 23:39
add a comment |
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,150518
1,150518
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.
– user10067412
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.
– user10067412
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
534
534
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.
– user10067412
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.
– 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
add a comment |
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?– user10067412
Nov 12 at 23:37