Describe the following in
version: "3.5" # docker-compose.Match with yaml version
app: # host.docker.Service name for which you want to use internal
- "host.docker.internal:184.108.40.206" #Match to the subnet specification below
- subnet: 220.127.116.11/16 #Specify not to overlap with other networks
If the firewall is running, you may need to allow access from the above subnet. Here is a command example of firewalld.
sudo firewall-cmd --permanent --zone=trusted --add-source=18.104.22.168/16
A special domain for accessing the host's network from a container, supported by docker for Mac and docker for Windows. Since mac has become the mainstream of developers, it is easy to use in projects, and linux users have troubles every time.
With these issues,
host.docker.internal will eventually be available on linux, but it will take some time before it is released, so I'll mention Workaround.
Rather, the work content is as described above, so I will write a commentary.
This file is automatically read when you execute the docker-compose command, so it is useful when writing your own settings that you do not want to include in the repository. However, when you use the -f option, it is not read automatically, so you need to specify this file as well.
Add the contents to
/ etc / hosts of the container.
All containers belong to the network named default unless otherwise specified, so if you write the settings here, they will be automatically reflected in all containers. The subnet set here is the default network subnet. Normally, the network subnet is automatically selected so that it does not overlap with the existing network, but this time I want to fix it, so I manually select and set it. The host belongs to all networks, and its IP seems to be "the lowest bit of the subnet mask is set to 1". (I didn't find such a statement in the documentation just because I tried it and said it was, so maybe it doesn't happen in some cases.) So, if you specify this IP in extra_hosts, you can assign a domain.