unraid / webgui

Unraid Web UI
147 stars 71 forks source link

[Docker] Add the ability to add multiple variables/labels/volumes/devices in a single text field #1813

Open andrebrait opened 1 month ago

andrebrait commented 1 month ago

Disclaimer: this is more of an RFC as I intend to implement this myself and submit a PR.

The problem

Adding multiple fields/variables is tedious. Workarounds do exist, but they are not elegant. While a solution like supporting full docker-compose syntax for templates would be arguably better, I think just having the ability to toggle a "list mode" for adding such things would already suffice and would be backwards-compatible with current templates.

The proposal

Add a checkbox (or special field type) to enable multi-line input for variables/labels/volumes/devices.

Alternatively, these could be fixed fields hidden behind the advanced mode. That's probably easier to implement.

Processing these and adding to the final docker run command should be easy enough.

Complications

The fields would probably be significantly different from the existing ones in that it must contain the definition of both keys and values (for variables/labels) or container mount and host path (for volumes/devices). This is not an issue if the decided implementation is based around fixed fields hidden behind the advanced mode.

In both cases, supporting the same syntax used by docker-compose is likely a good idea. There is no support for env files, naturally, but at least the same separators can be used, making copy-pasting from such files easier.

luzfcb commented 1 month ago

I don't know if it's the same thing as you thought, but I like OpenWRT's luci-app-dockerman option:

It has an option called Resolve CLI You click on it, paste the docker create or docker run command, and then submit it to the backend, the backend parses the command, and the page/form reloads with all fields filled

step1:

image

step2:

image

step3

All fields was filled and you are able to customize mode before creating the container

image

The most logic is implemented in Lua https://github.com/lisaac/luci-app-dockerman/blob/7292955a1b415bb60fa2e403bb3a437b4b7f7846/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua#L63C1-L363C4

(probable the ChatGPT can help to convert this function to PHP)

andrebrait commented 1 month ago

Strictly speaking, that's actually a next step I was going to propose once I had done these. Essentially I'd like it to support maybe also the Docker compose syntax for defining services.

(And I'd rather work on the logic by hand than trusting an LLM to hallucinate the right code. Parsing a command is easy enough so that porting from the logic in Lua is likely not the best path forwards here anyway. Very likely I'll have to rewrite whatever it produces anyway.)