大网数据广告活动
服务器运维问答

Docker: Map container port to single IPv6-address on host

· 52CE 我爱测

now that some of my server applications are packed into Docker containers, I'm trying to deploy them on my production servers. My containers should be accessible by IPv4 and IPv6 at the same time. Usually that is no problem: If y…

问题原文

原帖链接 · Thomas · CC BY-SA 3.0

now that some of my server applications are packed into Docker containers, I'm trying to deploy them on my production servers. My containers should be accessible by IPv4 and IPv6 at the same time. Usually that is no problem: If you map container ports to host ports e.g. via docker-compose, Docker will use available IPv6 and IPv4 addresses.

My problem is: There is not only one IPv4 and IPv6 address available on my server, but multiple. My application container should only use one specific IPv4 address and one specific IPv6 address of the host. You can bind a container port to a IPv4-address by using the following docker-compose syntax:

ports:
    - "127.0.0.1:8001:8001"

(See https://docs.docker.com/compose/compose-file/#ports)

Unfortunately I couldn't find any information how to do that with IPv6 addresses. Is there any way I can bind a container port to a single, specific IPv6 address on my Docker host?

已采纳解答

原帖链接 · BMitch · CC BY-SA 4.0

As of version 1.15 of docker-compose you can now use additional colons in the port definition for IPv6:

version: '3.3'

services:
  app:
    image: nginx
    ports: 
    - "::1:8080:80"

The relevant issue can be found here: https://github.com/docker/compose/issues/2663

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-04-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。