external-ip

External Ip Docker Image

自动构建

为Docker容器配置外部IP的工具,通过设置容器的EXTERNAL_IP环境变量,自动配置iptables路由容器流量至指定外部IP,需主机已分配该外部IP。

下载次数: 0状态:自动构建维护者:tozd仓库类型:镜像最近更新:
下载命令
点击查看

tozd/external-ip

DEPRECATED: Use com.docker.network.host_ipv4 bridge option since Docker v25. See https://github.com/docker-mailserver/docker-mailserver/pull/4330/files.

https://gitlab.com/tozd/docker/external-ip

Available as:

  • https://hub.docker.com/r/tozd/external-ip
  • https://gitlab.com/tozd/docker/external-ip/container_registry

Image inheritance

https://gitlab.com/tozd/docker/base ← https://gitlab.com/tozd/docker/dinit ← tozd/external-ip

Tags

  • ubuntu-bionic
  • ubuntu-focal
  • ubuntu-jammy
  • ubuntu-noble
  • alpine-38
  • alpine-310
  • alpine-312
  • alpine-314
  • alpine-316
  • alpine-318
  • alpine-320
  • alpine-322

Volumes

  • /var/log/dockergen: Log files when LOG_TO_STDOUT is not set to 1.

Variables

  • DOCKER_HOST: Where to connect to access Docker daemon to monitor for new containers. Default is /var/run/docker.sock inside the container.
  • LOG_TO_STDOUT: If set to 1 output logs to stdout (retrievable using docker logs) instead of log volumes.

Description

Run:

$ docker run --detach \
 --net=host --cap-add=NET_ADMIN --cap-add=NET_RAW \
 --volume /var/run/docker.sock:/var/run/docker.sock \
 --volume /run/xtables.lock:/run/xtables.lock \
 tozd/external-ip:ubuntu-bionic

After that, if any other Docker container has an environment variable EXTERNAL_IP set, with an IP address to use for containers external IP, iptables will be configured to route container's traffic from that external IP. Connections to other containers on the same Docker network keep the container's own address, except connections which Docker redirects from a published port back into a container. The external IP must be assigned on the host.

A chain named EXTERNAL_IP is created in the nat table into which all the rules are added. The chain is managed fully by the container: rules for containers which are not running anymore are removed, as are any other rules added to it. And one more empty chain is created after this one for any additional custom rules you might want to add, named AFTER_EXTERNAL_IP.

Please make sure /run/xtables.lock exists on the host before starting the container. This file ensures iptables locking is consistent between the host and the container, preventing race conditions that can cause containers to fail to start. If this file does not exist, Docker will incorrectly create it as a directory, which may cause issues both on the host and with the container.

When LOG_TO_STDOUT is set to 1, Docker image logs output to stdout and stderr. All stdout output is JSON.

docker-compose example

version: '3'

services:
  nat_manager:
    image: tozd/external-ip:ubuntu-bionic
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /run/xtables.lock:/run/xtables.lock
    network_mode: host
    cap_add:
      - NET_ADMIN
      - NET_RAW

  a:
    image: byrnedo/alpine-curl
    command: "-s http://ifconfig.me"
    environment:
      EXTERNAL_IP: XX.XX.XX.XX

  b:
    image: byrnedo/alpine-curl
    command: "-s http://ifconfig.me"
    environment:
      EXTERNAL_IP: YY.YY.YY.YY

Set XX.XX.XX.XX and YY.YY.YY.YY to your external IP address.

GitHub mirror

There is also a https://github.com/tozd/docker-external-ip, if you need to fork the project there.

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 external-ip 镜像标签

docker pull docker.xuanyuan.run/tozd/external-ip:<标签>

DockerHub 原生拉取命令

docker pull tozd/external-ip:<标签>
专业版 · 高速稳定拉取镜像
50GB 仅 ¥8/年
高速镜像下载在线技术支持专业版保障服务可用付费会员免广告