Skip to content

It is impossible do inspect Bun application inside docker using vscode #7490

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

Open
matepaiva opened this issue Dec 6, 2023 · 9 comments · May be fixed by #19884
Open

It is impossible do inspect Bun application inside docker using vscode #7490

matepaiva opened this issue Dec 6, 2023 · 9 comments · May be fixed by #19884
Labels
bug Something isn't working debugger Something to do with `bun --inspect` or the debugger docker An issue that occurs when running in Docker vscode Something to do with the VSCode extension

Comments

@matepaiva
Copy link

What version of Bun is running?

docker oven/bun:1-slim

What platform is your computer?

docker

What steps can reproduce the bug?

  1. create a simple bun application.
  2. add a script to your package.json like "watch": "bun --hot --inspect=ws://0.0.0.0:6499/forcingPrefix index.ts "
  3. create a Dockerfile to run it, like:
FROM oven/bun:1-slim as base
COPY . .
RUN bun install

USER bun

ENV NODE_ENV=development

EXPOSE 3000/tcp
EXPOSE 6499/tcp

CMD ["bun", "watch"]
  1. create a docker-compose.yaml, like:
version: "3.8"

services:
  bun-app:
    build: ./html-to-image-bun-server
    ports:
      - "3001:3000"
      - "6499:6499"
    expose:
      - 6499
    volumes:
      - ./html-to-image-bun-server:/home/bun/app
  1. run docker compose up
  2. create a .vscode/launch.json like:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "bun",
      "request": "attach",
      "name": "Attach to Bun",
      "url": "ws://127.0.0.1:6499/forcingPrefix",      
    }
  ]
}
  1. start debugging via vscode using "Attach to Bun" option. It starts fine.
  2. add a breakpoint to any line and do something (a request) to run that line. It will not stop at the line, but it should! ❌

What is the expected behavior?

I should be able to inspect a bun application inside a docker via websocket, but it does not work as supposed.

What do you see instead?

I can inspect it using the web bun debugger, but it does not work at vscode.

Additional information

Instead of "0.0.0.0", I tried to pass different values to inspect (at package.json and at launch.json), like "localhost" or "127.0.0.1". It does not work.

@matepaiva matepaiva added the bug Something isn't working label Dec 6, 2023
@paperclover paperclover added debugger Something to do with `bun --inspect` or the debugger docker An issue that occurs when running in Docker labels Dec 7, 2023
@robobun robobun added docker An issue that occurs when running in Docker and removed docker An issue that occurs when running in Docker labels Dec 7, 2023
@paperclover paperclover added the vscode Something to do with the VSCode extension label Dec 7, 2023
@ZeldOcarina
Copy link

Hey any news on this one?

@maciejopalinski
Copy link

maciejopalinski commented Jul 2, 2024

If you manually insert a debugger; line into your code, it will work, but it will try to open a file on the host machine, with a path from the docker container.
In Node.js debugger, you just had to specify the remoteRoot in launch.json example in the docs. I don't think remoteRoot exists in Bun extension for VS Code.

I captured the websocket communication using Wireshark just to confirm.

  1. VS Code sends the breakpoint
{"id":6,"method":"Debugger.setBreakpointByUrl","params":{"url":"/home/matthew/Projects/bun-test/src/main.ts","lineNumber":0}}
  1. Bun debugger inside docker acknowledges
{"result":{"breakpointId":"/home/matthew/Projects/bun-test/src/main.ts:0:0","locations":[]},"id":6}
  1. Bun reports parsed scripts, here is the one (id 1533) with debugger; on line 5:
{"method":"Debugger.scriptParsed","params":{"scriptId":"1533","url":"/usr/src/app/src/main.ts","startLine":0,"startColumn":0,"endLine":11,"endColumn":0,"isContentScript":false,"sourceURL":"/usr/src/app/src/main.ts","sourceMapURL":"[...]", ...
  1. Bun debugger stops on the line with debugger;
{"method":"Debugger.paused","params": {"callFrames": [{"callFrameId": "{\"ordinal\":0,\"injectedScriptId\":1}","functionName": "","location": {"scriptId": "1533", ...
  1. VS Code tries to open /usr/src/app/src/main.ts

In this example case, setting remoteRoot to /usr/src/app should simply fix the problem, but that option is just not available in Bun debugger for VS Code as far as I know.

@maciejopalinski
Copy link

I wanted to submit a patch myself, this seems like an easy fix, but I never touched Bun code base so I have no idea where to add my fix. I will leave it to the developers.

@ZeldOcarina @matepaiva
The workaround for it is to change the WORKDIR in the Dockerfile to the same path as on the host system. In my base it's WORKDIR /home/matthew/Projects/bun-test. It is a nasty workaround, but works well enough.

@ZeldOcarina
Copy link

There's an easier fix I've applied: I switched everything to npm!

@maciejopalinski
Copy link

There's an easier fix I've applied: I switched everything to npm!

😆😆😆 Yeah, I guess Bun is not ready to be a plug&play Node.js replacement... I hope it will eventually get there!

@maciejopalinski
Copy link

Will this get fixed anytime soon?

@patriksimms
Copy link

I wanted to submit a patch myself, this seems like an easy fix, but I never touched Bun code base so I have no idea where to add my fix. I will leave it to the developers.

@ZeldOcarina @matepaiva The workaround for it is to change the WORKDIR in the Dockerfile to the same path as on the host system. In my base it's WORKDIR /home/matthew/Projects/bun-test. It is a nasty workaround, but works well enough.

This was actually a really good fix for us. While beeing hacky, we build a portable solution.

This is our dockerfile (which also shows build secrets, which works also with the solution)

ARG BUN_VERSION=1.1.26
FROM oven/bun:${BUN_VERSION}-alpine as development

ARG WORKDIR_ENV
WORKDIR ${WORKDIR_ENV}
COPY package.json bunfig.toml bun.lockb ./
RUN --mount=type=secret,id=gitlab_npmrc,target=${WORKDIR_ENV}/.npmrc bun install --ignore-scripts --frozen-lockfile

Now you can set in your docker-compose file. Important: You have to expose the LOCAL_PWD env var to your system. We did not found a way that docker-compose could infer the pwd correctly. In your build pipeline you can now expose e.g. /app as the env var.

 build:
      context: .
      dockerfile: '.docker/Dockerfile.node'
      target: development
      args:
        - WORKDIR_ENV=$LOCAL_PWD

This is the launch config we use:

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "bun (docker)",
          "type": "bun",
          "request": "attach",
          "url": "ws://localhost:6499/tq1bwri63p",
      }
  ]
}

We still would be happy if bun fixes this by adding the the root properties

@alexwohlbruck
Copy link

alexwohlbruck commented May 24, 2025

is nobody using bun in docker? i'm very frustrated

the debug id in the url can be fixed with a custom prefix, eg:

bun run --hot --inspect=127.0.0.1:6499/debug src/index.ts

with this config & the docker container running in network_mode: host i can get the debugger working ONLY in the browser inspector. the VS code debugger will attach to the debugger server but none of the breakpoints work

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "bun",
      "request": "attach",
      "name": "Attach to Bun",
      "url": "ws://127.0.0.1:6499/debug",
    }
  ]
}

Image

  1. why must we have this running in host network mode? is this a technical limitation? for security?
  2. what may be going wrong with the vs code debugger? I can't get any debug logs for this to find out why the breakpoints don't function

@ZeldOcarina
Copy link

Use tsx, it's great for debugging in VSCode!

@Jarred-Sumner Jarred-Sumner linked a pull request May 24, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working debugger Something to do with `bun --inspect` or the debugger docker An issue that occurs when running in Docker vscode Something to do with the VSCode extension
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants