Nixpkgs: docker-compose suddenly needs sudo

Created on 23 May 2017  路  14Comments  路  Source: NixOS/nixpkgs

Issue description

docker-compose suddenly needs sudo

If I do not prefix docker-compose with sudo, it returns:

ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

The socket is fine:

# ls -al /var/run/docker.sock 
srw-rw---- 1 root docker 0 May 23 16:43 /var/run/docker.sock

We have make scripts that use docker-compose, so this is an issue because prefixing them with sudo will pollute the dev directory with root files.

Steps to reproduce

  • System is up to date with nixos-rebuild switch
  • in /etc/nixos/configuration.nix, virtualisation.docker.enable = true;
  • The computer crashed (was sleeping, ran out of battery) once.
  • As far as I know, nothing else changed.

Technical details

  • System: 17.09pre107265.0afb6d789c (Hummingbird)
  • Nix version: nix-env (Nix) 1.11.9
  • Nixpkgs version: "17.09pre107265.0afb6d789c"
  • Sandboxing enabled: build-use-sandbox = false

Most helpful comment

If it helps anyone, I was having this issue and it was caused by having files owned by root in my folder, most likely because I was mapping some folders as volumes, but I'm not 100% sure about that. I essentially ran this and things started being happy again:

sudo chown -R $USER:$USER .

Is there a way docker-compose can give a better error message here? I essentially binary searched my compose file paring it down until i had the most basic thing that worked which was very tedious.

All 14 comments

I can't reproduce on my system. Are you sure your user is in the docker group? Can the same user run docker ps?

Here's my system details:

$ nix-env --version
nix-env (Nix) 1.11.8

sam at crate in /data/docker/plex
$ nixos-version
17.03.1195.4d07c03462 (Gorilla)

sam at crate in /data/docker/plex
$ nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion
"17.03.1195.4d07c03462"

sam at crate in /data/docker/plex
$ docker-compose up -d
plex is up-to-date

In the same shell:

$ groups
users wheel tty audio video www-data networkmanager systemd-journal docker adbusers
$ docker-compose up --build
Building auth
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

However, having run sudo docker-compose up --build, docker-compose up now works.

docker-compose build also fails.

So it seems as if building containers only works with sudo, but running them is accessible to the normal user.

I have the same symptomas my computer run out of battery, it seems docker doesn't allow to save power in sleep mode or hibernate mode.

Technical details

  • 17.03.1602.040921d3da (Gorilla)
  • nix-env (Nix) 1.11.11

I cannot reproduce this with:

[nix-shell:~/dev/nixpkgs-tmp]$ cat docker-compose.yml 
version: '3'
services:
  web:
    build: .
    ports:
     - "5000:5000"
  redis:
    image: "redis:alpine"

[nix-shell:~/dev/nixpkgs-tmp]$ cat Dockerfile 
FROM python:3.4-alpine
CMD ["echo", "hello"]

Building and up work fine as user normally as well as after suspending.

Please re-open if you still have this issue and have a reproduction case.

I have the exact same problem.

my user can run docker ps but I cannot run 'docker-compose up' anymore.
Suddenly I need to run as root otherwise I get

ERROR: Couldn't connect to Docker daemon - you might need to run docker-machine start default.

Same problem here on Fedora 27

Please attach the log generated by strace -f -o dc.log docker-compose up.

Same problem here on Fedora 27, and if I run as sudo then it creates issues with me trying to write to the volume when I run my PHP application. The socket is verified to exist.

ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

If it helps anyone, I was having this issue and it was caused by having files owned by root in my folder, most likely because I was mapping some folders as volumes, but I'm not 100% sure about that. I essentially ran this and things started being happy again:

sudo chown -R $USER:$USER .

Is there a way docker-compose can give a better error message here? I essentially binary searched my compose file paring it down until i had the most basic thing that worked which was very tedious.

Unfortunately that did not fix the problem for me @ppg. Having the same bug over here. Why was this issue closed?!?!

I am also experiencing this issue

One of the reasons is that the current user has not been added to the docker group.
To check if the current user is in the docker group, we can use:

cat /etc/group | grep docker

If we do not see the current user in the output of the previous command, we will add it by using this command:

sudo gpasswd -a $USER docker

And lastly, we need to restart the docker service by using the command:

sudo service docker restart

Reauthenticating to gcloud worked for me:

gcloud auth login

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lverns picture lverns  路  3Comments

ob7 picture ob7  路  3Comments

grahamc picture grahamc  路  3Comments

matthiasbeyer picture matthiasbeyer  路  3Comments

copumpkin picture copumpkin  路  3Comments