Failing to run Docker's "Getting Started" guide

Hi,

I’m new to NixOS and Docker. I installed docker according to this Docker - NixOS Wiki guide.

This Nix “hello world” Docker tutorial worked for me: Building and running Docker images — nix.dev documentation.

But when I try to run Docker’s official “Getting Started” guide it immediately fails: Develop with containers | Docker Docs

  • docker compose watch did download all docker dependencies
  • But when it started the services, it couldn’t connect to port 80.
  • I installed rootless docker, so I thought changing it to port 2000 would fix it
  • docker compose watch now wouldn’t show an error, but Firefox couldn’t connect to https://localhost:2000 because of some connection error
  • Then I installed Docker with root privileges, rebooted, tried again with port 80, and now Firefox thought the connection was unsafe, and when I proceeded anyway there was a connection error

So what can I do to make Docker run this basic example project?

Hey. I think it would increase your chances of getting help if you added the configuration or at least a snippet of what you think is relevant.

From the guide:

Open your browser to http://localhost

from your post:

Firefox couldn’t connect to https://localhost:2000 because of some connection error

The site is not using TLS. The connection error is because you are trying to connect to an http service using https.

Regarding TLS: I also tried http://localhost:2000, but maybe Firefox uses TLS anyway.

My /etc/nixos/configuration.nix for Docker is:

# Docker - http://nixos.wiki/wiki/Docker
virtualisation.docker.enable = true;
virtualisation.docker.rootless = {
  enable = true;
  # set $DOCKER_HOST to the rootless Docker instance for normal users
  setSocketVariable = true;
};
users.extraGroups.docker.members = [ "kalua" ];
virtualisation.docker.daemon.settings = {
  data-root = "/home/kalua/dev/docker-data-root";
  userland-proxy = false;
};

After sudo nixos-rebuild switch and a reboot I tried the steps from the Docker “Getting started” guide:

git clone https://github.com/docker/getting-started-todo-app
cd getting-started-todo-app
docker compose watch

Edit: Then point your browser at http://localhost.

It would already be helpful to know if the above 3 steps work for someone else, or if there are some fundamental problems with that in the Nix world.

There are some incompatibilities, but it’s mostly from using rootless mode, I think if you were not using rootless mode it would work without any changes.

Listening on port 80 is not compatible with rootless mode. It also tries to do this, which assumes a system wide docker daemon:

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Making these two changes makes everything start up for me:

     ports:
-      - 80:80
+      - 2000:80
     volumes:
-      - /var/run/docker.sock:/var/run/docker.sock
+      - ${XDG_RUNTIME_DIR}/podman/podman.sock:/var/run/docker.sock

but I’m running podman, it looks like for docker you would use

${XDG_RUNTIME_DIR}/docker.sock

as the docker socket location

Also for testing try using

curl -v http://localhost:2000/

that will give a more useful error than firefox usually.

Thanks, that indeed solved the problem! It works in Firefox too. Now I’ll try to keep an eye open for any absolute paths that assume the file hierarchy standard with docker, and I’ll also give podman a go.

Also I did try not using rootless mode, and it still had problems. I only tested rootless mode with your changes now.