by Devin Yang

建立于: 2年前 ( 更新: 2年前 )

可用docker version检查,确认版本在Docker v20.10+
即可添加extra_hosts如下:

#=== php service ==========================
 php:
  build:
    context: ./dockerfiles
    dockerfile: Dockerfile-php82-${CPU-x86_64}
    args:
      USER_ID: ${USER_ID-1000}
      GROUP_ID: ${GROUP_ID-1000}
  image: ${PROJECT}_php
  extra_hosts:
    - "host.docker.internal:host-gateway"

这样我们就能在ping到host罗

dlaravel@37bc03f69cc5:/var/www/html$ ping host.docker.internal
PING host.docker.internal (172.17.0.1) 56(84) bytes of data.
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=1 ttl=64 time=0.049 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=2 ttl=64 time=0.067 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=3 ttl=64 time=0.061 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=4 ttl=64 time=0.056 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=5 ttl=64 time=0.058 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=6 ttl=64 time=0.047 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=7 ttl=64 time=0.059 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=8 ttl=64 time=0.059 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=9 ttl=64 time=0.067 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=10 ttl=64 time=0.086 ms

或许你们会好奇这个172.17.0.1的IP是在那里可以看到,我们可以用,就能找到了
因为host-gateway就是我们 default bridge network ip。

docker inspect bridge|grep Gateway
                    "Gateway": "172.17.0.1"

Tags: docker phpenv

Devin Yang

文章内容无法一一说明,如果您有什么不了解处,欢印提问哦:)

No Comment

Post your comment

需要登入才可留言!

类似文章


docker

用树莓派安装Docker及docker-compose

本文简单介绍我们如何在Raspberry Pi上安装docker及docker-compose。

certbot,docker,ftp

curlftpfs介绍及手动证书申请

情境分享,设想您有WebHosting,他只提供FTP连线,然后您想手动的方式申请证书。在本篇分享我如何使用Docker安装curlftpfs,并且挂载远程主机FTP数据夹,然后在容器内运行certbot申请SSL证书。撇除证书申请不说,我初次发觉到curlftpfs这个命令时,觉的满有意思的,特别是如果你用的是MacOS用户,手边没有一个满意的FTP软体时。您跟我一样喜欢在命令行上打滚,或许您应该也会喜欢这个命令。🤭

docker,cli

Docker容器格式化显示

我觉的如果要写一些自动化功能,或许能够格式化的输出容器内容还满有用的。以下一些Docker容器格式化显示命令的参考范例