Cannot enable IPv6 for docker by configuration
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
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; })}";
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 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.
Maybe it will work with virtualisation.docker.extraOptions if I add the "fixed-cidr-v6" field. Haven't tried.
I marked this as stale due to inactivity. → More info
I guess this is till an issue.
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";
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.
@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"
}
}
It should be possible to set:
virtualisation.docker.daemon.settings.log-opts.max-size = "10m";
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.