2

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?

1
  • I haven't used Docker, but I assume the process is similar to VM situation. With VMs, I create a bridge interface, which has host physical interface and VM virtual interface as a member. Then, inside the VM I assign the public IPv6 address which I want the VM to have. Replace the VM with container in the description and you should have the way to do it. Apr 4, 2017 at 8:33

2 Answers 2

3

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

0
1

My solution is to bind all container exposed ports to 127.0.0.1 and then forward external v4 and v6 IP-connections via HAProxy to 127.0.0.1. Maybe not the nicest way to do it, but a solution for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .