Skip to main content

Disable IPv6 in docker compose

I have a docker-compose project that I am trying to run on my server, which does not have IPv6 enabled. Whenever I try to run the container, I get the following error message:

nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)

I figured that is because IPv6 is not enabled on my server (it is managed by a third party, so I can’t touch that), so I tried disabling IPv6 for docker-compose, so far without any luck.

I tried adding

sysctls:
      net.ipv6.conf.all.disable_ipv6: 1

on my config file, but then I received the following error Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: open /proc/sys/net/ipv6/conf/all/disable_ipv6: no such file or directory: unknown

How can I disable IPv6 in docker-compose, either for this particular container or system-wide to not have issues like this?

This is my current config

    container_name: cont-nginx
    networks:
        - cont
    image: nginx:latest
    depends_on:
        - cont-app
    restart: always
    ports:
        - "880:880"
        - "4443:4443"
    sysctls:
        - net.ipv6.conf.all.disable_ipv6=1
    volumes:
        - ./nginx.conf:/etc/nginx/nginx.conf

networks: cont: driver: bridge

Solution : Disabling IPv6 for the docker’s network should do the job:

networks: cont: driver: bridge enable_ipv6: false Also, maybe you should consider removing this from your nginx conf

listen [::]:80; because [::] is for IPv6.