containers / toolbox

Tool for interactive command line environments on Linux
https://containertoolbx.org/
Apache License 2.0
2.57k stars 220 forks source link

Support for custom commands upon entering container #1302

Open josecastillolema opened 1 year ago

josecastillolema commented 1 year ago

Is your feature request related to a problem? Please describe. Today, for running custom commands when entering a toolbox container the recommendations is to have a custom .bashrc entry, i.e.: toolbox.sh. This makes the toolbox configuration split into two files, the Containerfile (i.e.: Containerfile) and the bash script ^.

Describe the solution you'd like To follow best IaC/declarative practices, it would be better to have all the configuration related to the container in one place, the Containerfile. For that to happen, toolbox should support a way to place custom commands somewhere in the Containerfile (i.e. the RUN section).

debarshiray commented 1 year ago

Hey, @josecastillolema ! I remember we discussed this before.

In this specific Containerfile there's:

# Initialize opam
RUN useradd $user
USER $user
RUN opam init --disable-sandboxing
RUN opam install -y dune merlin ocaml-lsp-server odoc ocamlformat utop dune-release

# Clean
USER root
RUN mkdir /usr/share/opam/
RUN cp -r /home/jose/.opam /usr/share/opam
RUN userdel -r jose
RUN dnf clean all \
    && rm -rf /var/cache/dnf
RUN echo "toolbox create -i localhost/ocaml:5 ocaml"

I remember you wanted ~/.opam inside the container. Isn't that already the case, because HOME is always bind mounted from the host? So everything inside HOME should be available inside the container.

debarshiray commented 1 year ago

I remember that you had mentioned offering a hook in the Containerfile to specify commands to be run inside the container.

I can think of two broad categories:

These are likely necessary to be run only once when the container starts. The entry point can read these from the Containerfile hook and run them.

These are likely necessary to be run on every invocation of toolbox enter and toolbox run, and will be trickier to implement with a Containerfile hook. It reminds me of my idea of a toolbox shell command. It would run inside the container between the podman exec and the final process inside the container that the user interacts with. It could then take care of reading the Containerfile hook.

All that makes me wonder if we need two separate Containerfile hooks to differentiate between those cases, and what those hooks might be. I am apprehensive of using CMD for this because there are images out there with unexpected things in CMD. eg., the fedora base images have CMD /bin/bash, which won't terminate on its own. I think we would need something explicitly specific to Toolbx.

josecastillolema commented 1 year ago

Some custom annotation in the Dockerfile comments specific to toolbox could do the trick as well.

secretmango commented 8 months ago

another feature supported by distrobox :D

distrobox-enter boxname -- command works normally, on toolbox it does nothing

bellegarde-c commented 7 months ago

another feature supported by distrobox :D

distrobox-enter boxname -- command works normally, on toolbox it does nothing

toolbox run -c boxname command

secretmango commented 7 months ago

this means it should work right?