Disable ip v6 in docker container

111.2k views Asked by At

I have ipv6 enabled on docker host but there is one particular container where ipv6 is causing issues. Is there a way to launch a container without ipv6 support, either through command line argument or dockerfile directive?

7

There are 7 answers

0
icecrime On BEST ANSWER

Unfortunately there isn't: --ipv6 is a daemon-wide flag that cannot be overridden on a per-container basis.

4
d3ming On

Two options:

  1. Run docker with --dns-opt='options single-request'. See docs
  2. Run with --sysctl net.ipv6.conf.all.disable_ipv6=1. See discussion here
0
Rodrigo Marins On

Worked for me:

docker run -d -i -t  --name django_1.0 --sysctl 
net.ipv6.conf.all.disable_ipv6=1 -p 192.168.20.148:8000:8000/tcp -p 
192.168.20.148:8000:8000/udp -p 192.168.20.148:3000:3000/tcp -p 
192.168.20.148:3000:3000/udp IMAGE_NAME

root:~# netstat -tlp | grep -i docker

tcp  0  0 ip-192-168-20-148.:8000 *:*    LISTEN      4598/docker-proxy

tcp  0  0 ip-192-168-20-148.:3000 *:*    LISTEN      4642/docker-proxy
1
Freethinker On

To disable ipv6, run docker container with:

-e "extra_params=--o:net.proto=IPv4"

Tested on Ubuntu 20.04, collabora office container.

UPDATE: But this did not worked runing pgadmin container, so added extra line:

-e "PGADMIN_LISTEN_ADDRESS=0.0.0.0" \

3
tripleee On

If you are looking to disable IPv6 from within a Linux Docker image, this seems to work even when the file system is read-only.

sysctl net.ipv6.conf.all.disable_ipv6=1
sysctl net.ipv6.conf.default.disable_ipv6=1

These commands are privileged; run with sudo if you are not root.

0
Arnau Sistach Reinoso On

The way I think of disabling ipv6 with Docker is by creating a network without ipv6.

For example

docker network create --ipv6=false disable_ipv6

And runs with:

docker run --network disable_ipv6
docker build --network disable_ipv6
2
tokhi On

Its kind of tricky. I just had the same issue what I did was to run the container with the ip:

docker run --name YourDockerContainer -p 192.168.99.100:80:80

This will start the container on this ip: 192.168.99.100.