My n8n deployment environment is Windows 11+Docker desktop. I want to obtain the local IP address of the host’s network card. How can I do it? Can Java script code be implemented through code nodes? How to write JavaScript code?
If your question hasn’t been asked before, please follow the template below. Skip the questions that are not relevant to you. →
Describe the problem/error/question
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
The safest way to reach the host from within Docker is to use the internal domain host.docker.internal instead of the IP address.
Docker containers, including the host, usually run in their own network. Because of this, the Windows machine will have multiple IP addresses. host.docker.internal resolves to the Docker network’s internal IP address.
What are you trying to do? Do you just need to access internal services? If so, using host.docker.internal should be enough.
Do you really need the host machine’s IP address? If so, you’ll probably need to pass it as an environment variable when starting the container.
There’s also an option to use the host machine’s network when starting the container (--network host), but Docker containers on Windows and MacOSX run in their own virtual machine.