by Devin Yang

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

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

需要登入才可留言!

类似文章


openai,flax,docker

用容器跑OpenAI官方教程的Python(Flax)

如果您登录了openai的网站,可在此处看到官方的教程说明https://beta.openai.com/docs/quickstart/build-your-applicationAPI的KEY的申请,就在这页的下方就有按钮了+ Create new secret key本篇教您用Docker跑官方OpenAI运行环境。

docker

Docker防毒攻略

最近刚看玩延禧攻略,就想来介绍个MacOS扫毒攻略。 这篇文章,教大家用如何用Docker搞定MacOS扫毒。 简单介绍,我们如何透过docker使用防毒软体扫毒。 这里假定目前我的目录是在我的家目录中,所以${PWD}就是目前的所在目录,会被挂载到container内的scan数据夹。 所以,使用clamscan -r /scan/,时就能扫描所有的挡案罗,加上-r的参数会使用递归的方式一层一层的进入子目录扫描。

php,docker,dlaravel

我创建的phpenv容器环境简单介绍

没时间拍介绍影片,我就来随便抓些画面介绍我使用的容器环境deviny/phpenv。https://github.com/DevinY/phpenvphpenv算是我之前D-Laravel开源项目的进化版本,概念上延用了很多Dlaravel的操作方式。容器的更新上偏向使用者自行控制去Build自己的image,所以我不太会去更动版号了,其实D-Laravel的php版号,好像我也很久没动啦:p