Hey hey, I am trying to run k3 in a

Hey hey, I am trying to run k3 in a container, with the following:
# syntax=docker/dockerfile:1
FROM rancher/k3s:latest

# Expose the required ports for K3s
EXPOSE 6443
EXPOSE 443
EXPOSE 80

# Set the default command to run K3s server
CMD ["server", "--disable", "traefik"]
# syntax=docker/dockerfile:1
FROM rancher/k3s:latest

# Expose the required ports for K3s
EXPOSE 6443
EXPOSE 443
EXPOSE 80

# Set the default command to run K3s server
CMD ["server", "--disable", "traefik"]
And this is my code:
export class MyContainer extends Container {
defaultPort = 6443;
requiredPorts = [6443, 443, 80];
// ...
}

app.get("/readyz", async (c) => {
const container = getContainer(c.env.MY_CONTAINER);
return await container.fetch(c.req.raw);
});
// ...
export class MyContainer extends Container {
defaultPort = 6443;
requiredPorts = [6443, 443, 80];
// ...
}

app.get("/readyz", async (c) => {
const container = getContainer(c.env.MY_CONTAINER);
return await container.fetch(c.req.raw);
});
// ...
I get the following:
⎔ Container image(s) ready
⎔ Starting local server...
✘ [ERROR] Error checking if container is ready: connect(): Connection refused: container port not found. Make sure you exposed the port in your container definition.
✘ [ERROR] Error checking if container is ready: internal error; reference = r48029i07cer86vit2h90t6i
✘ [ERROR] Error checking if container is ready: internal error; reference = df2ceaqdffenqqhpp6ka9igg
✘ [ERROR] Error checking if container is ready: internal error; reference = gist59tegar22c3tp1iaj7ac
✘ [ERROR] Error checking if container is ready: connect(): Connection refused: container port not found. Make sure you exposed the port in your container definition.
Container error: [Error: Container exited with unexpected exit code: 1] { exitCode: 1 }
▲ [WARNING] workerd/io/actor-sqlite.c++:647: warning: NOSENTRY SQLite alarm handler canceled with requestScheduledAlarm.; scheduledTime = 1753139731.815s; localAlarmState.orDefault(kj::UNIX_EPOCH) = 1753139733.074s; actorId = b60d370ee54d17e273624ceb809e666d47bc8cb445b274c648f7e06520b5a613
[wrangler:info] GET /readyz 500 Internal Server Error
⎔ Container image(s) ready
⎔ Starting local server...
✘ [ERROR] Error checking if container is ready: connect(): Connection refused: container port not found. Make sure you exposed the port in your container definition.
✘ [ERROR] Error checking if container is ready: internal error; reference = r48029i07cer86vit2h90t6i
✘ [ERROR] Error checking if container is ready: internal error; reference = df2ceaqdffenqqhpp6ka9igg
✘ [ERROR] Error checking if container is ready: internal error; reference = gist59tegar22c3tp1iaj7ac
✘ [ERROR] Error checking if container is ready: connect(): Connection refused: container port not found. Make sure you exposed the port in your container definition.
Container error: [Error: Container exited with unexpected exit code: 1] { exitCode: 1 }
▲ [WARNING] workerd/io/actor-sqlite.c++:647: warning: NOSENTRY SQLite alarm handler canceled with requestScheduledAlarm.; scheduledTime = 1753139731.815s; localAlarmState.orDefault(kj::UNIX_EPOCH) = 1753139733.074s; actorId = b60d370ee54d17e273624ceb809e666d47bc8cb445b274c648f7e06520b5a613
[wrangler:info] GET /readyz 500 Internal Server Error
Any idea what could be the issue? 🤔
13 Replies
Aster
AsterOP2mo ago
Checking with another test container: https://github.com/stefanprodan/podinfo It seems like it doesn't like to expose several ports 🤔 When I restrict the container to 1 port, my podinfo works When retrying with k3s, but exposing only 1 port EXPOSE 6443, I get a [Error: Container exited with unexpected exit code: 137] when hitting the /readyz endpoint ^^ After bumping the container to use "instance_type": "standard" I know get a beautiful [Error: Container exited with unexpected exit code: 1] { exitCode: 1 } error 😅
Aster
AsterOP2mo ago
Hum maybe I need to wait for bigger instances 😦 https://docs.k3s.io/installation/requirements#hardware
Requirements | K3s
K3s is very lightweight, but has some minimum requirements as outlined below.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
peterp
peterp2mo ago
We have the same issue - the problem seems to be when exposing multiple ports
つんでれd
つんでれd2mo ago
Hmm strange. I have exposed multiple ports on my containerized application and working fine for now.
peterp
peterp2mo ago
Downgrading to Vite 6, from 7, appears to have resolved this
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
つんでれd
つんでれd2mo ago
I run a Bun server like this in container.
Bun.serve({
async fetch(request, server) {
return new Response('Hello World');
},

port: 8081
});

Bun.serve({
async fetch(request, server) {
return new Response('Hello World from 8080');
},

port: 8080
});
Bun.serve({
async fetch(request, server) {
return new Response('Hello World');
},

port: 8081
});

Bun.serve({
async fetch(request, server) {
return new Response('Hello World from 8080');
},

port: 8080
});
with this Dockerfile:
FROM oven/bun:latest

COPY container-src ./

RUN bun install

CMD ["bun", "index.ts"]

EXPOSE 8080 8081
FROM oven/bun:latest

COPY container-src ./

RUN bun install

CMD ["bun", "index.ts"]

EXPOSE 8080 8081
My @cloudflare/containers package is latest as well, and using wrangler dev to run it locally. I can't confirm K3s is working because running Dockerfile manually with docker build and docker run also doesn't work because of my host OS.
peterp
peterp2mo ago
GitHub
GitHub - redwoodjs/machinen: A web based text-editor for RedwoodSDK
A web based text-editor for RedwoodSDK. Contribute to redwoodjs/machinen development by creating an account on GitHub.
peterp
peterp2mo ago
Let me know if you need some orientation around it? It's working now - so I guess upgrading vite to v7 would create a repro.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
peterp
peterp2mo ago
Oh! I'm building/ using RedwoodSDK Which needs the Cloudflare Vite Plugin. They just added support for containers! I assumed you worked at Cloudflare, lol!
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?