How can you make the Docker container use the host machine's '/etc/hosts' file?

后端 未结 11 1813
夕颜
夕颜 2020-12-23 11:21

I want to make it so that the Docker container I spin up use the same /etc/hosts settings as on the host machine I run from. Is there a way to do this?

I

11条回答
  •  无人及你
    2020-12-23 11:53

    Also you can install dnsmasq to the host machine, by the command:

    sudo apt-get install dnsmasq
    

    And then you need to add the file /etc/docker/daemon.json with content:

    {
        "dns": ["host_ip_address", "8.8.8.8"],
    }
    

    After that, you need to restart the Docker service by command sudo service docker restart

    This option forces to use the host DNS options for every Docker container. Or you can use it for a single container, and the command-line options are explained by this link. Also docker-compose options are supported (you can read about it by this link).

提交回复
热议问题