Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fumaz opened this issue Oct 20, 2023 · 17 comments
Open

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

Fumaz opened this issue Oct 20, 2023 · 17 comments
Labels

Comments

@Fumaz
Copy link

Fumaz commented Oct 20, 2023

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
Copy link

ptrxyz commented Oct 23, 2023

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

@ptrxyz
Copy link

ptrxyz commented Oct 23, 2023

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
Copy link
Owner

apocas commented Oct 23, 2023

Investigating

@apocas
Copy link
Owner

apocas commented Oct 23, 2023

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

@hazelnutcloud
Copy link

hazelnutcloud commented Oct 24, 2023

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

@hazelnutcloud
Copy link

This seems to be a problem with bun. See oven-sh/bun#6055

@apocas
Copy link
Owner

apocas commented Oct 24, 2023

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.

@apocas apocas changed the title Specifying socketPath but Dockerode is using HTTP. Specifying socketPath but Dockerode is using HTTP. (bun.js) Oct 30, 2023
@apocas apocas pinned this issue Oct 30, 2023
@recanman
Copy link

recanman commented Feb 24, 2024

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
Copy link

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

@recanman
Copy link

recanman commented Mar 7, 2024

There is a pull request, but no response yet.

@Anprotaku
Copy link

Anprotaku commented Mar 7, 2024

@recanman it looks like they merged another pull request that should fix it
oven-sh/bun#9284

Should be safe to close this issue

@recanman
Copy link

recanman commented Mar 8, 2024

Great, thank you!
Mentioning author: @Fumaz

@dionjwa
Copy link

dionjwa commented May 21, 2024

I am using [email protected] via deno, and I am still getting this issue.

@devingfx
Copy link

Same issue with Deno 1.43.6, dockerode 4.0.2, with:

import Docker from 'npm:dockerode'
const docker = new Docker({socketPath: '/var/run/docker.sock'})
const images = await docker.listImages()
console.log( images )

Got:

error: Uncaught (in promise) TypeError: error sending request for url (http://localhost/images/json): error trying to connect: tcp connect error: Connection refused (os error 111)
    at async node:http:397:21

@Karrq
Copy link

Karrq commented Oct 11, 2024

I'm also getting the same issue with Deno 2.

I think it's related due to the fact that it's the same issue as what bun had, and other deno users will be able to find this and not waste time debugging why it's happening

@LazerJesus
Copy link

same issue with deno 2. is there an issue yet? couldnt find it if there is

@adamazad
Copy link

Same issue with Deno v2.1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests