The Docker container cannot resolve the domain name in the LAN, even if you configure the hosts domain name mapping of the local host. The Docker environment is different from wamp or xampp. For domain name resolution within the LAN, Docker needs to configure the hosts file in the Docker container.
Solution
After entering the Docker container, configure domain name resolution in the hosts file.
# 进入 docker 容器 docker exec -it my_web /bin/bash # 修改 hosts 文件 vi /etc/hosts # 添加域名解析规则 192.168.99.100 example.test # 或者,直接追加字符串到指定的文件末尾 echo '192.168.99.100 example.test' >> /etc/hosts
After saving and exiting, use the ping command to verify whether the ping can pass.
docker-machine.exe ssh default ping example.test
It should be noted that every time the container (service) is restarted, the newly added configuration in the /etc/hosts file in the container will become invalid, so it needs to be reconfigured.
For more related tutorials, please pay attention to the docker tutorial column on the PHP Chinese website.
The above is the detailed content of How to do domain name resolution in docker. For more information, please follow other related articles on the PHP Chinese website!