1

How can I find the file descriptor that a process reads input from?

Background

I run a Vite (pronounced veet) server when developing in an Alpine container. Currently I login to the container and manually start Vite with the command vite --host '0.0.0.0' --port 3000, it takes over the console and allows input interactively. So I can do things like restart the server when file changes don't register on the Docker volume bind mount in the container (Windows being silly).

Problem

I would like to have the container run this command on startup. When I do I lose the ability to send commands as Docker does not pass them along.

Container running Vite server

I then made a script that runs pnpm run dev &; thinking I could get the process ID of the Vite server, then send input to that file descriptor with echo "h" > /proc/17/fd/0, but nothing happens. I also tried PID 33. I assumed that I'm sending input to the wrong place. But How can I find the correct file descriptor, if there is any.

PS output in container

PID USER TIME COMMAND 1 root 0:00 node /usr/local/bin/pnpm run dev 17 root 0:00 node /root/task-01/node_modules/.bin/../vite/bin/vite.js --host 0.0.0.0 --port 3000 33 root 0:00 /root/task-01/node_modules/.pnpm/@[email protected]/node_modules/@esbuild/linux-x64/bin/esbuild --service=0.20. 39 root 0:00 sh 47 root 0:00 ps 

Disclaimer: This should now be solved with Docker watch since I will no longer need to manually restart the server when files change; but I want to see if its possible as this can be useful for other cases. Also, don't shame me for running as root, I don't normally do that.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.