Enabling IPv6
Our load balancing operates through IPv6 for stability across our network as it grows. Many docker images are generated in ways that bind IPv6 ports and will work out of the box. Others, e.g. those created with build services like cog or truss may not. If you are having problems with Container Gateway connections this may be the case. However your dreams of running on SaladCloud are not lost, you just need to set an IPv6 host. Alternatively, adding socat to your image is an easy way to route IPv6 requests and get cooking.
Checking IPv6 in your container
To check if IPv6 is enabled in your container, run a terminal in your container and run the following commands:
Adapt this to the appropriate package manager for the base distro of your container, e.g.
apk add
for alpine
If you see output with an IPv6 line, you’re good to go!
However if there is no tcp6 line, follow the instructions below to add IPv6 support to your container.
Configuring IPv6
Using an IPv6 host
If you are defining the host of your server directly, e.g. with a host of localhost
, replace it with the IPv6
equivalent ::
Equivalently replace a host of 0.0.0.0
with the IPv6 equivalent*
.
Uvicorn
uvicorn main:app --host '::' --port 1234
Gunicorn
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind '[::]:1234'
Node.js
Express.js
Fastify
IPv6 with socat in custom containers
If you have direct access to the dockerfile used to create your image, you can modify it to install and start socat
which will forward IPv6 to IPv4. For the example below, you would enter port 8888 for SaladCloud, which would then be
routed to IPv4 port 8080. Adapt as needed for your setup. Alternatively, the socat
command can be included in an
entryfile or setup script. Once you’ve rebuilt the image, check with netstat
as above to verify it has worked.
IPv6 with cog through socat
If you are using cog to create your container, a few small changes can enable
socat
to route IPv6 to IPV4 within the container.
-
Add socat to the
system_packages
section ofcog.yaml
. For example, -
In predict.py (or other file included in the
predict
section ofcog.yaml
) addimport os
, and addos.system("socat TCP6-LISTEN:8888,fork TCP4:127.0.0.1:5000 &")
tosetup
. Update5000
to the port your container is expecting. The other port, here, 8888 is what would be used when setting up the container group deployment.
Was this page helpful?