nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

Cannot enable IPv6 for docker by configuration

Open mawis opened this issue 7 years ago • 11 comments

By default docker does not enable IPv6 for containers. To enable IPv6 in containers, one has to modify /etc/docker/daemon.json by adding at least { "ipv6":true } to it.

See https://docs.docker.com/v17.09/engine/userguide/networking/default_network/ipv6/

Due to what I found, there is no way to generate daemon.json with any of the NixOS configuration options virtualisation.docker.*. Sure I am able to generate /etc/docker/daemon.json manually and it also works afterwards. But somehow it feels wrong to do so. Actually the point of NixOS seems to be, that I have a central place where I can configure my system declarative. Having additional configuration files I place manually causes the system to have a non-reproducible configuration.

Therefore I think there should be additional options to enable IPv6 and also to configure fixed-cidr-v6 in the same file.

Actually I do know, that his is not really a bug, but a feature request. But I opened it as a bug, because I found no other way to submit feature requests.

If this could be considered for inclusion, I may also submit a PR, if this is wanted by the maintainers.

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.1.21, NixOS, 19.03.173408.bd6ba87381e (Koi)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.2.2
  • channels(root): "nixos-19.03.173408.bd6ba87381e"
  • channels(matthias): "home-manager-19.03"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Maintainer information:

attribute:
  - docker
module:
  - virtualization.docker

mawis avatar Sep 09 '19 09:09 mawis

I also happened to need to modify the docker daemon configuration and figured out a quick way to do it without changing nixpkgs.

virtualisation.docker.extraOptions = "--config-file=${pkgs.writeText "daemon.json" (builtins.toJSON { ipv6 = true; })}";

alinnow avatar Sep 10 '19 14:09 alinnow

As of Docker 19.03, the content of /etc/docker/daemon.json needs to be something like this

{
  "ipv6": true,
  "fixed-cidr-v6": "fd00::/80"
}

(ref: https://medium.com/@skleeschulte/how-to-enable-ipv6-for-docker-containers-on-ubuntu-18-04-c68394a219a2)

The documentation https://docs.docker.com/config/daemon/ipv6/ has 12 upvotes, 241 downvotes, indicating it is not telling the whole truth.

I tried @alanpearce 's method, but observed that /etc/systemd/system/docker.service content to be unchanged, that is, no --config-file flag.

rht avatar May 26 '20 11:05 rht

@rht I think the systemd files are not located at the standard location at /etc/systemd/system but in the nix store. Setting options via virtualisation.docker.extraOptions, but I haven't tried the ipv6 specific ones.

Moredread avatar Aug 02 '20 04:08 Moredread

Maybe it will work with virtualisation.docker.extraOptions if I add the "fixed-cidr-v6" field. Haven't tried.

rht avatar Aug 02 '20 05:08 rht

I marked this as stale due to inactivity. → More info

stale[bot] avatar Jan 30 '21 03:01 stale[bot]

I guess this is till an issue.

asbachb avatar Aug 14 '21 04:08 asbachb

Hi! I worked on an virtualisation.docker.daemonConfig option. One that will be converted to JSON. It makes it easy to enable ipv6 for example using:

virtualisation.docker.daemonConfig.ipv6 = true;
virtualisation.docker.daemonConfig."fixed-cidr-v6" = "fd00::/80";

That said, it should already be possible to add ipv6 support using:

virtualisation.docker.extraOptions = "--ipv6 --fixed-cidr-v6 fd00::/80";

bobvanderlinden avatar Oct 13 '21 19:10 bobvanderlinden

Hi @bobvanderlinden! Thanks for the tip with using virtualisation.docker.extraOptions. That works very well. I'm also looking forward to use virtualisation.docker.daemon.settings in the next release of NixOS.

mawis avatar Mar 05 '22 18:03 mawis

@bobvanderlinden Thanks so much for the great feature.

Sorry, but how to set a nested value like the log max-size please?

root@sidendemosen:/home/das# cat /etc/docker/daemon.json 
{
	"userland-proxy": false,
	"iptables": true,
	"ip6tables": false,
	"experimental": false,
	"metrics-addr": "0.0.0.0:9323",
	"log-driver": "json-file",
        "log-opts": {
                "max-size": "10m",                <----- ?
                "max-file": "10"
        }
}

randomizedcoder avatar Jul 18 '24 20:07 randomizedcoder

It should be possible to set:

virtualisation.docker.daemon.settings.log-opts.max-size = "10m";

bobvanderlinden avatar Jul 19 '24 06:07 bobvanderlinden

Thanks Bob!

This is great!

Nix config example

  virtualisation.docker.enable = true;
  virtualisation.docker.daemon.settings = {
    data-root = "/home/das/docker/";
    userland-proxy = false;
    experimental = true;
    ipv6 = true;
    fixed-cidr-v6 = "fd00::/80";
    metrics-addr = "0.0.0.0:9323";
    log-driver = "json-file";
    log-opts.max-size = "10m";
    log-opts.max-file = "10";
  };

Becomes

[das@t14:~/nixos/t14]$ ps ax |grep dockerd
1039704 ?        Ssl    0:00 /nix/store/gffv48mh99irwv4rk097jq98hj9kiv21-moby-24.0.9/libexec/docker/dockerd --config-file=/nix/store/c4dlljhmyy11lfgj8zsr8gka2c1dljlz-daemon.json
1040215 pts/7    S+     0:00 grep dockerd

[das@t14:~/nixos/t14]$ cat /nix/store/c4dlljhmyy11lfgj8zsr8gka2c1dljlz-daemon.json
{
  "data-root": "/home/das/docker/",
  "experimental": true,
  "fixed-cidr-v6": "fd00::/80",
  "group": "docker",
  "hosts": [
    "fd://"
  ],
  "ipv6": true,
  "live-restore": true,
  "log-driver": "json-file",
  "log-opts": {
    "max-file": "10",
    "max-size": "10m"
  },
  "metrics-addr": "0.0.0.0:9323",
  "userland-proxy": false
}

I'm probably not actually going to log like this, because the default logging to journald is more suitable, but for some projects json logging might be useful.

randomizedcoder avatar Jul 19 '24 15:07 randomizedcoder