Docker-在Mac上编写extra_hosts

我试图添加一个新的主机到我的Nginx容器与Docker-compose的extra_hostsconfiguration。 出于某种原因,我不能使它工作。 我使用Docker for Mac 17.06 CE和Docker-Compose v3稳定。 这是我的configuration:

nginx: build: ./docker/nginx container_name: nginx ports: - '80:80' volumes: - "${PROJECT_ROOT}:/var/www/html:ro" networks: - server extra_hosts: - 'test.local:127.0.0.1' depends_on: - php restart: always 

我也尝试添加额外的主机与我的Mac的IP,但它不响应。

UPDATE

出于某种原因,您需要编辑Mac上的/ etc / hosts文件来添加新的主机。 extra_hostsconfiguration什么都不做。

您需要在Mac中编辑这个文件: /etc/sudoers

添加这个:

 127.0.0.1 test.local 

例如:

 sudo sh -c "echo 127.0.0.1 test.local >> /etc/hosts" 

如果不起作用,请尝试使用其他文件: /private/etc/hosts

请参阅: https : //www.tekrevue.com/tip/edit-hosts-file-mac-os-x/