Docker Community Forums

Share and learn in the Docker community.

[SOLVED]The Host not resolve container name

I’m new to Docker.
I have an application that runs in a docker container. Everything works well but the dns doesn’t work.
The host machine can ping the container’s IP address but not its name.
The address of the container 172.17.0.2.
I tried to insert
nameserver 172.17.0.1
in the /etc/resolvconf.conf file but it doesn’t work.
Conversely, the container can resolve the ip and host machine name.
So, the problem is on the host machine.
Both machines are Archlinux.
Any help will be greatly appreciated

Why would you expect that the host would be able to resolve hostnames of containers?

A container in the same container network can resolve the hostname, container name or network alias of a container in the same network (except on the default bridged network).

Accessing a container from the host or even a different host in the same local network is a bad practice. Publish ports and use {host]:{published port} to access your service from the host or any other host in the same local network.

thanks for replies.
Now I understand well.
I’d like to ask you another question.

I created a network via the command

docker network create mynet

This is the output of the network inspect command

docker inspect mynet 
[
    {
        "Name": "mynet",
        "Id": "7ab437655a2fcd46f5cc5371310741f3fc674e3428c608349f921ad078f1a150",
        "Created": "2020-02-28T19:08:59.062644596+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

I created two containers that run on this network.

The first
ip address 172.18.0.2
name Mariadb

The second
ip address 172.18.0.3
name Plasma

If I ping their ip address it works but If I try to ping their names it doesn’t work.
Both run on the same mynet network
Why doesn’t it work?
Thanks again

Please share the actual docker-compose.yml or docker run commands you used to create the containers.

it worked. Thanks so much.
Mark as solved