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,git

用docker-compose快速建立私有的git服務

如何快速建立一個開箱即用的Gogs環境呢? 本文介紹採用docker-compose.yml快速建立gogs環境。

php,docker,dlaravel

我建立的phpenv容器環境簡單介紹

沒時間拍介紹影片,我就來隨便抓些畫面介紹我使用的容器環境deviny/phpenv。https://github.com/DevinY/phpenvphpenv算是我之前D-Laravel開源專案的進化版本,概念上延用了很多Dlaravel的操作方式。容器的更新上偏向使用者自行控制去Build自己的image,所以我不太會去更動版號了,其實D-Laravel的php版號,好像我也很久沒動啦:p 

docker gui,docker

如何在Container內執行X client及X Window簡介(docker gui)

由於Mac OS Leopard版之後,Apple已不在內建X11,要求大家使用open source的XQuartz,所以如果您想在Mac OS上,顯示X client的畫面,記得先安裝Mac OS專用的X11 server:https://www.xquartz.org/index.html首先,在MacOS環境開始前,請記得安裝XQuartz,並且記得啟動允許網路連線要打勾哦