Docker run and docker exec error

Hello Nixos,

I’m a newbie to Nixos and have been trying it out on my setup for some days.

I have bother docker and podman installed. Docker was working fine until a few days ago. Now, I get the following errors when I try running docker run

$ docker run --rm hello-world
http: invalid Host header
FAIL

Here is the info from docker info: docker_info - Pastebin.com

Any help is appreciated. I’m at my wits :slight_smile:

1 Like

I experienced the same problem and was able to rollback to a version which worked for me.

The origin of the problem seems to be an update of the Go programming language in the Moby project: Golang client fails to attach to streams with "http: invalid Host header" with go1.20.6, go1.19.11 · Issue #45935 · moby/moby · GitHub

May I ask how? I’m absolute Nix noob and currently evaluating whether it will work as a replacement for current OS. I enabled it like this:

virtualisation.docker.enable = true;

I’m a NixOS-newbie too :wink:

For me this command worked:

nixos-rebuild switch --rollback

But it just goes back to the previous generation. If you have changed your system in the meantime multiple times, this approach won’t work.

You can list available generations by

nix-env --list-generations --profile /nix/var/nix/profiles/system

I guess you need to use

nix-env --switch-generation XX -p /nix/var/nix/profiles/system

to go back to a specific generation. Maybe this discussion will help.

That sadly won’t help me, I literally installed the system today for the first time ever, I never had a configuration with working docker.

You should be able to go back to before the issue with this: Docker fails to run containers · Issue #244159 · NixOS/nixpkgs · GitHub

It sounds like the fix will be available in nixos 23.05 very soon. It’s already in nixos unstable.

I hope this doesn’t discourage you from trying nixos. I’ve only been using it for a few weeks, but I’ve been really happy with what I’ve seen–among many other things, you can tweak or upgrade your system entirely risk-free because it takes just a few seconds to roll back if anything goes wrong. Of course there’s a big learning curve if you’re coming from a more traditional distro, which is the main reason you don’t see more people using it.

I worked around this issue by pinning Docker itself to an earlier version, courtesy of tomgray on Github:

  # pin docker to older nixpkgs: https://github.com/NixOS/nixpkgs/issues/244159
  nixpkgs.overlays = [
    (let
      pinnedPkgs = import(pkgs.fetchFromGitHub {
        owner = "NixOS";
        repo = "nixpkgs";
        rev = "b6bbc53029a31f788ffed9ea2d459f0bb0f0fbfc";
        sha256 = "sha256-JVFoTY3rs1uDHbh0llRb1BcTNx26fGSLSiPmjojT+KY=";
      }) {};
    in
    final: prev: {
      docker = pinnedPkgs.docker;
    })
  ];

I simply pasted this in configuration.nix next to virtualisation.docker.enable = true; and it’s a little bit nicer than pinning the entire nixpkgs to an earlier version.

In a little while when the fix gets pushed through I’ll remove this snippet again.

4 Likes

thank you for this! always wondered how to use different version of docker when it’s only virtualisation.docker.enable = true

Thanks! Marked this as the answer as it is reliable and only affects the part of the system that’s broken!

The issue has been resolved upstream @Rikudou

Please update your system. Docker should simply work now

sudo nix-channel --update
sudo nixos-rebuild switch

Thanks, I’ll check it out!

I believe the fix has not been implemented yet for Docker Compose. The docker command apparently runs, but docker compose still has issues.

I won’t link the Github issue again (to avoid the Discourse bot continuing to clutter the issue thread) but you can follow the link in this previous comment to track the latest: