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

移除所有docker containers及docker images的指令

有時在自己的環境中試了一堆container或是images,如何全部移掉系統中所有的images及container 呢?這些指令提供給大家參考..

docker

ubuntu上安裝docker-compose

簡單介紹我如何在ubuntu上安裝docker-compose. 還滿容易的。

docker,Synology

如何修改Synolog Nas上Docker的日誌記錄驅動

我的Synolog Nas上,預設跑了一個奇怪的logging driver叫db,如何修改為正常使的json-file呢? 在Synolog的Nas他的Daemon config file較特殊,放在/var/packages/Docker/etc/目錄下, 叫dockerd.json。