Home  >  Article  >  Operation and Maintenance  >  How to do domain name resolution in docker

How to do domain name resolution in docker

尚
Original
2020-03-24 16:39:497023browse

How to do domain name resolution in docker

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn