# Cannot connect to the Docker daemon

**URL:** <https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [March 7, 2024, 11:48am UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776 "2024-03-07T11:48:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dal](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/dal/32/8363_2.png) [@Dal](https://community.traefik.io/u/Dal)\
**Post date:** [March 7, 2024, 11:48am UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/1 "2024-03-07T11:48:36Z")

</div>

Hi.  
I'm struggling to get traefik running properly.  
It cannot connect to the docker daemon, and gives me these errors:

```auto
level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" providerName=docker
level=error msg="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 10.921124173s" providerName=docker

```

I run the docker container as non-root, with a username dockeruser.  
I have run the commands:

```auto
sudo groupadd docker
sudo usermod -aG docker $USER

```

And everything seems to run fine otherwise. I have other containers up and running

In the traefik docker compose file I have set this:

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

```

Any tips?  
thank you

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 7, 2024, 12:30pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/2 "2024-03-07T12:30:36Z")

</div>

Share your full Traefik static and dynamic config, and `docker-compose.yml` if used.

Which user is active inside Docker container?

---

<div class="post-metadata">

**Author:** ![Dal](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/dal/32/8363_2.png) [@Dal](https://community.traefik.io/u/Dal)\
**Post date:** [March 7, 2024, 12:59pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/3 "2024-03-07T12:59:48Z")

</div>

Hi, thanks for answering.  
Her is a link to [traefik.yml](https://pastebin.com/JgudgW9b)  
and a link to [fileConfig.yml](https://pastebin.com/1qctebAZ)  
Here is the [docker-compose.yml](https://pastebin.com/CdaN429X)

How do I know for sure what user is active inside the docker?  
It is supposed to be "dockeruser"

The user should have access.  
When running the command **stat /var/run/docker.sock** , it says:

```auto
stat /var/run/docker.sock
  File: /var/run/docker.sock
  Size: 0 Blocks: 0 IO Block: 4096 socket
Device: 17h/23d Inode: 697 Links: 1
Access: (0660/srw-rw----) Uid: ( 0/ root) Gid: ( 997/ docker)
Access: 2024-03-07 14:02:36.128012382 +0100
Modify: 2024-02-26 14:55:19.239746804 +0100
Change: 2024-02-26 14:55:19.243746804 +0100

```

and the user docker user is member of the docker group, as stated by **groups dockeruser** :

```auto
dockeruser : dockeruser sudo docker

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 7, 2024, 2:04pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/4 "2024-03-07T14:04:24Z")

</div>

Running inside or outside the container?

Note that you can't have multiple traefik static config, either `traefik.yml`, compose `command` or env vars,

---

<div class="post-metadata">

**Author:** ![Dal](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/dal/32/8363_2.png) [@Dal](https://community.traefik.io/u/Dal)\
**Post date:** [March 7, 2024, 2:33pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/5 "2024-03-07T14:33:00Z")

</div>

Not sure what happened, but after a apt update && apt upgrade and a reboot, it seems that the errors are gone.  
I see this in the log:  
**Provider connection established with docker 25.0.4 (API 1.44)" providerName=docker**  
I'm guessing that is a good thing.

But I still cannot see other containers in the traefik dashboard.

For example code\_server:

```auto
version: "3.8"
services:
  code_server:
    container_name: code_server
    restart: unless-stopped
    image: lscr.io/linuxserver/code-server:latest
    networks:
      - elastic
    volumes:
      - ./data:/config
      - /home/dockeruser/docker:/1_Docker_Containers
    labels:
      traefik.enable: true
      traefik.http.routers.code_server.rule: Host("cs.domain.tld")
      traefik.http.routers.code_server.entryPoints: https
      traefik.http.routers.code_server.tls: true
    environment:
      - TZ=Europe/Oslo
      - PASSWORD=Password02
      - PUID=1001
      - PGID=1001
    ports:
      - 8444:8443
networks:
  elastic:
    external: true

```

---

<div class="post-metadata">

**Author:** ![Dal](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/dal/32/8363_2.png) [@Dal](https://community.traefik.io/u/Dal)\
**Post date:** [March 7, 2024, 2:34pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/6 "2024-03-07T14:34:05Z")

</div>

> [@bluepuma77](#):
>
> Note that you can't have multiple traefik static config, either `traefik.yml`, compose `command` or env vars,

I'm aware. And as far as I know, I don't have any multiple entries active. There are a bunch that are commented out, though

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 7, 2024, 5:34pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/7 "2024-03-07T17:34:51Z")

</div>

You labels are in JSON style, but need to be in ENV VAR style.

---

<div class="post-metadata">

**Author:** ![Dal](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/dal/32/8363_2.png) [@Dal](https://community.traefik.io/u/Dal)\
**Post date:** [March 7, 2024, 7:01pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/8 "2024-03-07T19:01:45Z")

</div>

You mean like this:

```auto
labels:
      - traefik.enable = true
      - traefik.http.routers.code-server.rule = Host('cs.domain.tld')
      - traefik.http.routers.code-server.entryPoints = https
      - traefik.http.routers.code-server.tls = true

```

Didn't help

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 7, 2024, 7:05pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/9 "2024-03-07T19:05:01Z")

</div>

Like this:

```auto
labels:
      - traefik.enable=true
      - traefik.http.routers.mywhoami.rule=Host(`whoami.example.com`)
      - traefik.http.services.mywhoami.loadbalancer.server.port=80

```

Source: [simple Traefik example](https://github.com/bluepuma77/traefik-best-practice/tree/main/docker-traefik-dashboard-letsencrypt)

---

<div class="post-metadata">

**Author:** ![Dal](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/dal/32/8363_2.png) [@Dal](https://community.traefik.io/u/Dal)\
**Post date:** [March 7, 2024, 7:41pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/10 "2024-03-07T19:41:28Z")

</div>

> [@bluepuma77](#):
>
> ```auto
> labels:
> - traefik.enable=true
> - traefik.http.routers.mywhoami.rule=Host(`whoami.example.com`)
> - traefik.http.services.mywhoami.loadbalancer.server.port=80
> 
> ```

This did the trick!  
Aaah, hours and hours banging head against the wall are finally over!

Thank you, thank you, THANK YOU

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [March 10, 2024, 7:41pm UTC](https://community.traefik.io/t/cannot-connect-to-the-docker-daemon/21776/11 "2024-03-10T19:41:28Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
