npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

host-docker-internal

v0.2.4

Published

Fetch Docker host IP/hostname from inside container.

Readme

host-docker-internal

Fetch Docker host IP/hostname from inside containers.

在容器内部获取 Docker 宿主机的 IP 或主机名。

🔍 What it does

Helps you quickly fetch the IP or hostname of the Docker host from inside a container, making it easy to access services on the host or in other containers.

帮你在容器内部,快速获取 Docker 宿主机的 IP 或主机名,以便访问宿主机或其他容器中的服务。

🚀 When to use it

This library comes in handy when you encounter any of the following situations:

  • 🐧 When Docker runs on Linux (not macOS or Windows), you can't directly use host.docker.internal
  • ⚙️ When it's inconvenient to add --add-host=host.docker.internal:host-gateway during docker run
  • 🌍 When you don't want to switch between localhost and host.docker.internal between development and production environments
  • 💡 When you face any of the above but don't want to implement the fetching logic yourself

当你遇到以下任意情况时,本库可以派上用场:

  • 🐧 当 Docker 在 Linux 而不是 macOS 或 Windows 上运行时,无法直接使用 host.docker.internal
  • ⚙️ 当不方便在 Docker run 时添加 --add-host=host.docker.internal:host-gateway
  • 🌍 当你不想在开发环境与生产环境之间,来回切换 localhosthost.docker.internal
  • 💡 当你遇到以上几种情况,但又不想自己实现获取逻辑

📦 Install

npm install host-docker-internal

💻 Example

Docker Host

import { getDockerHost, isValidIp } from 'host-docker-internal';

const host = getDockerHost();
console.log(host);
console.log(isValidIp(host));
console.log(host === 'host.docker.internal');

await fetch(`http://${host}:3000/api/hello`);

Container IP

import { getContainerIp, isValidIp } from 'host-docker-internal';

const containerIp = getContainerIp();
console.log(containerIp);
console.log(isValidIp(containerIp));

📝 Remark

  1. During local development and debugging (not in a container), host is 127.0.0.1
  2. When the container runs on macOS or Windows, host is host.docker.internal
  3. When the container runs on Linux, host is the host machine's IP
  4. If fetching fails, host defaults to 172.17.0.1
  1. 本地开发调试时(不在容器中),host127.0.0.1
  2. 容器运行在 macOS 或 Windows 上时,hosthost.docker.internal
  3. 容器运行在 Linux 上时,host 为宿主机 IP
  4. 如果获取失败,host 为默认值 172.17.0.1