Wrangler x Docker

Hey guys I need some help setting up wrangler (dev) inside a docker container. The project i want to containerize and run locally would be: https://github.com/lyc8503/UptimeFlare This would be my Dockerfile: https://github.com/Its4Nik/UptimeFlare/blob/main/Dockerfile This would be the wrangler-dev.toml
name = "uptimeflare_worker"
main = "src/index.ts"
compatibility_date = "2023-11-08"
kv_namespaces = [{ binding = "UPTIMEFLARE_STATE", id = "UPTIMEFLARE_STATE" }]
name = "uptimeflare_worker"
main = "src/index.ts"
compatibility_date = "2023-11-08"
kv_namespaces = [{ binding = "UPTIMEFLARE_STATE", id = "UPTIMEFLARE_STATE" }]
The error I am getting is this one:
Failed to load .env file "/app/worker/.dev.vars": Error: ENOENT: no such file or directory, open '/app/worker/.dev.vars' at Object.openSync (node:fs:573:18) at Object.readFileSync (node:fs:452:35) at tryLoadDotEnv (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:158864:72) at loadDotEnv (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:158873:12) at getVarsForDev (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:197634:18) at getBindings (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205523:10) at getBindingsAndAssetPaths (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205404:20) at getDevReactElement (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205076:40) at startDev (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205140:60) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { errno: -2, code: 'ENOENT', syscall: 'open', path: '/app/worker/.dev.vars'
Failed to load .env file "/app/worker/.dev.vars": Error: ENOENT: no such file or directory, open '/app/worker/.dev.vars' at Object.openSync (node:fs:573:18) at Object.readFileSync (node:fs:452:35) at tryLoadDotEnv (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:158864:72) at loadDotEnv (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:158873:12) at getVarsForDev (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:197634:18) at getBindings (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205523:10) at getBindingsAndAssetPaths (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205404:20) at getDevReactElement (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205076:40) at startDev (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:205140:60) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { errno: -2, code: 'ENOENT', syscall: 'open', path: '/app/worker/.dev.vars'
And I couldn't find any information for the .dev.vars file... Thanks in advance! If needed I can provide more information
GitHub
GitHub - lyc8503/UptimeFlare: 📈 Free and serverless uptime monitori...
📈 Free and serverless uptime monitoring / status page on Cloudflare Workers, with Geo-specific checks - lyc8503/UptimeFlare
GitHub
UptimeFlare/Dockerfile at main · Its4Nik/UptimeFlare
Contribute to Its4Nik/UptimeFlare development by creating an account on GitHub.
3 Replies
kian
kian8mo ago
That’s not an error, that’s just a warning you’re seeing because you’re running it with a debug log level probably
Tech-Nik
Tech-NikOP8mo ago
ohhh i see okay then the other message is the error, one sec im gonna spin up my server again
Your worker has access to the following bindings:
- KV Namespaces:
- UPTIMEFLARE_STATE: UPTIMEFLARE_STATE
Starting local server...
[wrangler-ProxyWorker:dbg] Updated `Request.cf` object cache!

/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:29573
throw a;
^

Error: spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
path: '/usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
spawnargs: [
'serve',
'--binary',
'--experimental',
'--socket-addr=entry=localhost:9999',
'--external-addr=loopback=localhost:34009',
'--control-fd=3',
'-',
'--verbose'
]
}

Node.js v20.13.1
Your worker has access to the following bindings:
- KV Namespaces:
- UPTIMEFLARE_STATE: UPTIMEFLARE_STATE
Starting local server...
[wrangler-ProxyWorker:dbg] Updated `Request.cf` object cache!

/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:29573
throw a;
^

Error: spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
path: '/usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
spawnargs: [
'serve',
'--binary',
'--experimental',
'--socket-addr=entry=localhost:9999',
'--external-addr=loopback=localhost:34009',
'--control-fd=3',
'-',
'--verbose'
]
}

Node.js v20.13.1
so this would be the correct error ig (I dont have anz experience with cloudflare workers so please excuse me) any*
$ docker run --name test --rm uptimeflare:latest
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/app/wrangler'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Node.js v20.13.1
$ docker run --name test --rm uptimeflare:latest
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/app/wrangler'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Node.js v20.13.1
I don't understand why wrangler doesn't exist inside the docker container, well the files are there but i still get the error. As you can see, the files exist:
# Use Node.js 20 Alpine as base image
FROM node:20-alpine AS base

# Update package index and install necessary dependencies
RUN apk update

# Create and set the working directory
WORKDIR /app

# Copy the application code to the working directory
COPY ./data /app

# Install global npm packages and local dependencies
RUN npm install -g npm && \
npm install --save-dev wrangler

# Create a .env file
RUN touch .env

# Define volume for /app
VOLUME [ "/app" ]

# Expose port 9999
EXPOSE 9999

# Set the default command to run the development server
CMD ["wrangler", "dev", "--local", "-c", "worker/wrangler-dev.toml", "--node-compat", "--port", "9999", "--log-level", "debug"]
# Use Node.js 20 Alpine as base image
FROM node:20-alpine AS base

# Update package index and install necessary dependencies
RUN apk update

# Create and set the working directory
WORKDIR /app

# Copy the application code to the working directory
COPY ./data /app

# Install global npm packages and local dependencies
RUN npm install -g npm && \
npm install --save-dev wrangler

# Create a .env file
RUN touch .env

# Define volume for /app
VOLUME [ "/app" ]

# Expose port 9999
EXPOSE 9999

# Set the default command to run the development server
CMD ["wrangler", "dev", "--local", "-c", "worker/wrangler-dev.toml", "--node-compat", "--port", "9999", "--log-level", "debug"]
Ok I got a new error now, since wrangler wasnt install globally.
docker run --name test --rm uptimeflare:latest
🪵 Writing logs to "/root/.config/.wrangler/logs/wrangler-2024-05-17_09-08-42_848.log"
⛅️ wrangler 3.57.0
-------------------
[WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.

- KV Namespaces:
- UPTIMEFLARE_STATE: UPTIMEFLARE_STATE
Starting local server...
[wrangler-ProxyWorker:dbg] Updated `Request.cf` object cache!

/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:29749
throw a;
^

Error: spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
path: '/usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
spawnargs: [
'serve',
'--binary',
'--experimental',
'--socket-addr=entry=localhost:9999',
'--external-addr=loopback=localhost:36931',
'--control-fd=3',
'-',
'--verbose'
]
}

Node.js v20.13.1
docker run --name test --rm uptimeflare:latest
🪵 Writing logs to "/root/.config/.wrangler/logs/wrangler-2024-05-17_09-08-42_848.log"
⛅️ wrangler 3.57.0
-------------------
[WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.

- KV Namespaces:
- UPTIMEFLARE_STATE: UPTIMEFLARE_STATE
Starting local server...
[wrangler-ProxyWorker:dbg] Updated `Request.cf` object cache!

/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:29749
throw a;
^

Error: spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
path: '/usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd',
spawnargs: [
'serve',
'--binary',
'--experimental',
'--socket-addr=entry=localhost:9999',
'--external-addr=loopback=localhost:36931',
'--control-fd=3',
'-',
'--verbose'
]
}

Node.js v20.13.1
docker run --name test --rm -p 9999:9999 uptimeflare:latest
⛅️ wrangler 3.57.0
-------------------
▲ [WARNING] --local is no longer required and will be removed in a future version.

`wrangler dev` now uses the local Cloudflare Workers runtime by default. :tada:


▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.


Your worker has access to the following bindings:
- KV Namespaces:
- UPTIMEFLARE_STATE: UPTIMEFLARE_STATE
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:9999
⎔ Reloading local server...
docker run --name test --rm -p 9999:9999 uptimeflare:latest
⛅️ wrangler 3.57.0
-------------------
▲ [WARNING] --local is no longer required and will be removed in a future version.

`wrangler dev` now uses the local Cloudflare Workers runtime by default. :tada:


▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.


Your worker has access to the following bindings:
- KV Namespaces:
- UPTIMEFLARE_STATE: UPTIMEFLARE_STATE
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:9999
⎔ Reloading local server...
never mind got it to work with another node image, still thank for your help
Rumon
Rumon4mo ago
It's Alpine image which is causing the problem. Use a slim image (node:lts-slim for example). Had to learn it the hard way LOL.
Want results from more Discord servers?
Add your server