by Devin Yang
(This article was automatically translated.)

Published - 1 year ago ( Updated - 1 year ago )

You can check the docker version, confirm that the version is Docker v20.10+
you can add extra_hosts as follows:

#=== 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"

In this way, we can ping to the 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

Maybe you will be curious about where the IP of 172.17.0.1 can be seen, we can use it, and we can find it
Because host-gateway is our default bridge network ip.

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

Tags: docker phpenv

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


wordpress, d-laravel, docker, docker-compose

How to install Wordpress with D-Laravel

An 8-minute teaching video, introducing the installation of Wordpress on D-Laravel. D-Laravel is a docker-compose Laravel framework development environment, but it does not mean that it cannot be used to install other things. This video introduces the use of D-Laravel to install non-Laravel PHP projects, You can learn the usage of related instructions on D-Laravel: ./create --host usage, docker-compose up -d and ./console mysql usage, The database connection setting method after D-Laravel v1.0.0.

linux,docker

How to execute X client and X Window in Container (docker gui)

Today I will talk to you about X, not iPhone X, nor X-Men, but X Window System, He is the main graphical interface display component of the current Linux system. Since it is very easy to expand and modularize, it has been used since it was established in 1986. The X Window system adopts the Client/Server architecture, which splits the application program and the display into two. The application program of X Windows is usually called X Client, and the display is the well-known X Server. The X client communicates with the X server through the X protocol (X protocol), which is an asynchronous network communication protocol.

docker

How to update or rebuild D-Laravel's FPM Image

Sometimes, the docker image will undergo some corrections or add more plug-ins, how do we update the image in the computer? It's very simple, use docker pull [use the image], if you want to create your own image is also feasible...