apocas / dockerode

Docker + Node = Dockerode (Node.js module for Docker's Remote API)
Apache License 2.0
4.29k stars 461 forks source link

Specifying socketPath but Dockerode is using HTTP. (bun.js) #747

Open Fumaz opened 9 months ago

Fumaz commented 9 months ago

Hi, I'm initializing dockerode like this:

const docker = new Docker({socketPath: '/var/run/docker.sock'});

but when I use it, it gives the following error:

Could not get container information. ConnectionRefused: Unable to connect. Is the computer able to access the url?
path: "http://localhost/containers/b81d1747b4d9/json"

I am using Bun.

ptrxyz commented 9 months ago

An into the same problem ... not sure how that would happen. Maybe a permission thing?

ptrxyz commented 9 months ago

Maybe it matters: my Docker daemon version is 1.24, this is my test code:

import Docker from 'dockerode';
const docker = new Docker({ socketPath: '/var/run/docker.sock' });

The error:

/tmp/dockerode · sudo bun run index.ts
Error: ConnectionRefused: Unable to connect. Is the computer able to access the url?
 path: "http://localhost/containers/json?all=true"

Debug info:

/tmp/dockerode · ls -la /var/run/docker.sock
srw-rw---- 1 root docker 0 Oct 18 16:16 /var/run/docker.sock

/tmp/dockerode · docker info
Client:
 Version:    24.0.6
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 2
 Server Version: 24.0.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc sysbox-runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8c087663b0233f6e6e2f4515cee61d49f14746a8.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.5.7-zen2-1-zen
 Operating System: Arch Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 23.26GiB
 Name: nine
 ID: 29c770ff-e2ff-4c97-84e9-1e3da89486ae
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
apocas commented 9 months ago

Investigating

apocas commented 9 months ago

I can't reproduce that :( Tried exactly the same scenario bun and nodejs.

hazelnutcloud commented 9 months ago

running into same problem. using bun v1.0.7 on mac

hazelnutcloud commented 9 months ago

This seems to be a problem with bun. See https://github.com/oven-sh/bun/issues/6055

apocas commented 9 months ago

Now I can reproduce it using bun (forgot mocha was evoking node) :) Indeed is seems something related with bun, not much we can do right now.

recanman commented 5 months ago

Temporary solution I'm using:

Run this command:

socat TCP-LISTEN:3000,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock

Use it like this:

new Dockerode({protocol: 'http', host: 'localhost', port: 3000})
Anprotaku commented 4 months ago

Hello, is there any fix for this issue to get linux socket to work?

recanman commented 4 months ago

There is a pull request, but no response yet.

Anprotaku commented 4 months ago

@recanman it looks like they merged another pull request that should fix it https://github.com/oven-sh/bun/pull/9284

Should be safe to close this issue

recanman commented 4 months ago

Great, thank you! Mentioning author: @Fumaz

dionjwa commented 2 months ago

I am using dockerode@4.0.2 via deno, and I am still getting this issue.