Docker desktop on ubuntu 24.04 socket daemon mount failed

  • Issue type
    cant access to the docker.sock in docker-desktop for monitoring with telegraf

  • OS Version/build

$ uname -a 
Linux ubuntu 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.1 LTS
Release:	24.04
Codename:	noble
$ docker version  --format '{{json .Server}}'   
{"Platform":{"Name":"Docker Desktop 4.34.2 (167172)"},"Components":[{"Name":"Engine","Version":"27.2.0","Details":{"ApiVersion":"1.47","Arch":"amd64","BuildTime":"Tue Aug 27 14:15:15 2024","Experimental":"false","GitCommit":"3ab5c7d","GoVersion":"go1.21.13","KernelVersion":"6.10.4-linuxkit","MinAPIVersion":"1.24","Os":"linux"}},{"Name":"containerd","Version":"1.7.20","Details":{"GitCommit":"8fc6bcff51318944179630522a095cc9dbf9f353"}},{"Name":"runc","Version":"1.1.13","Details":{"GitCommit":"v1.1.13-0-g58aa920"}},{"Name":"docker-init","Version":"0.19.0","Details":{"GitCommit":"de40ad0"}}],"Version":"27.2.0","ApiVersion":"1.47","MinAPIVersion":"1.24","GitCommit":"3ab5c7d","GoVersion":"go1.21.13","Os":"linux","Arch":"amd64","KernelVersion":"6.10.4-linuxkit","BuildTime":"2024-08-27T14:15:15.000000000+00:00"}
  • App version

telegraf:1.30

  • Steps to reproduce

using this docker compose :

services:
  whoami:
    image: traefik/whoami:v1.10
    ports:
      - 8080:80 
  telegraf: 
    image: telegraf:1.30
    user: telegraf:1000
    volumes:
      - /home/seb/.docker/desktop/docker.sock:/var/run/docker.sock
      - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
  influxdb:
    image: influxdb:latest
    ports:
      - 86:8086
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_ORG: myorg 
      DOCKER_INFLUXDB_INIT_BUCKET: mybucket
      DOCKER_INFLUXDB_INIT_USERNAME: admin
      DOCKER_INFLUXDB_INIT_PASSWORD: adminpass
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: mytoken

wiht this telegraf.conf file:

[[outputs.influxdb_v2]]
  urls = ["http://influxdb:8086"]
  token = "mytoken"
  organization = "myorg"
  bucket = "mybucket"
[[inputs.docker]]
  endpoint = "unix:///var/run/docker.sock"
  container_names = [ ]

=> error in trelegraf :
[inputs.docker] Error in plugin: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

  • further information:
    $ docker context ls
    NAME DESCRIPTION DOCKER ENDPOINT ERROR
    default Current DOCKER_HOST based configuration unix:///var/run/docker.sock
    desktop-linux * Docker Desktop unix:///home/seb/.docker/desktop/docker.sock
  • i’m used to use this kinf of docker compose file in “default” context with this volume /var/run/docker.sock mounted and telegraf:984 user with no issues

what i’m doing wrong ?

You can’t mount a unix socket into a virtual machine. The Docker Daemon has its socket inside the virtual machine of Docker Desktop. The one on your host is just to help you connect from the host. So you should mount the one in the VM

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

I know it could be confusing, but it should work with Desktop. At lest this is how I do on macOS.