Querying Docker from Server
Unanswered
Sun bear posted this in #help-forum
Sun bearOP
Hello! I'm trying to make a game panel similar to pterodactyl or WISP and trying to get logs and start docker containers from the front end. Currently im using "dockerode" for the query and "zustand" to keep the logs of servers persistant between refreshes without having to re-query (plus the store function is just 10x easier compared to other ones ive tried). I cant seem to get dockerode working even behind self-wrapping it. Sometime I get errors such as "fs" doesn't exist which means that its trying to build to the client which it shouldn't as all of it is system calls.
Dockerode: https://github.com/apocas/dockerode
Zustand: https://github.com/pmndrs/zustand
If anyone already has some solution to this problem, I'm more than happy to change any deps.
Current code will be below.
Dockerode: https://github.com/apocas/dockerode
Zustand: https://github.com/pmndrs/zustand
If anyone already has some solution to this problem, I'm more than happy to change any deps.
Current code will be below.
3 Replies
Sun bearOP
// store.ts
// docker.ts
import { create } from "zustand"
interface ServerState {
logs: string[]
addLog: (log: string) => void
}
export const useServerStore = create<ServerState>()((set) => ({
logs: ["Test!"],
addLog: (log: string) => set((state) => ({ logs: [...state.logs, log] }))
}))// docker.ts
import Docker from "dockerode"
import { useServerStore } from "@/lib/store"
const docker = new Docker({})
export const streamLogs = async (containerId: string) => {
const state = useServerStore()
try {
const container = docker.getContainer(containerId)
const logStream = await container.logs({
follow: true,
stdout: true,
stderr: true
})
logStream.on("data", (chunk) => {
const log = chunk.toString()
console.log(log)
state.addLog(log)
})
} catch (err) {
console.error(`Error streaming logs for container ${containerId}`, err)
}
}Any help is appreciated!
Sun bearOP
here is one of the errors