by Devin Yang

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

可用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

D-Laravel上.env及docker-compsoe小教室

本文介绍,当我们使用D-Laravel的.env加载多个yml档时,为何docker-compose ps官方命令无法列出所有使用中的服务。 但在D-Laravel上的./console ps确能正常显示,那官方的docker-compose命令因如何使用才能有相同的效果呢?

docker,dlaravel

D-Laravel 1.5.5变更说明

D-Laravel的fpm image在php 7.2.1以前是使用docker php官方的dockerfile重build的, 并且所以我可以指定了fpm的默认的owner是dlaravel, --with-fpm-user=USER Set the user for php-fpm to run as. (default: nobody) --with-fpm-group=GRP Set the group for php-fpm to run as.

docker

如何简单的用Docker创建internet命令行的测速进程呢?

如何简单的用Docker创建internet命令行的测速进程呢? 这里我们使用python的进程speedtest-cli 会用Docker主要的用例,例如我想要在我的NAS内进行测速, 虽然我的NAS内有python,但没有pip命令,这时用Docker感觉上安全很多, 当然前题您的NAS需能跑Docker:)。 或者,我在MacOS的环境,我不想安装speedtest-cli到我的MacOS中。 这时用Docker简单的自建简单的运行环境还满不错的。