-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide shims for well-known binaries, which can only run on the host, inside the toolbox containers #145
Comments
I think it'll be dramatically simpler if we add |
Running podman inside the toolbox can be immensely useful. I work with many projects where build scripts is just calling docker images, and being able to run those scripts inside the toolbox can be really useful. There might create hard to detect issues with bind mounts outside the home directory that would reflect the silverblue host and not the toolbox though. |
I'll add |
I build a derivative toolbox
I then create a symbolic link to
NOTE: the list of commands that a user wants proxied to the host probably is different for every user so we should probably just create a generic way to configure it and then let the users do that themselves. You then execute things from within toolbox, but it gets proxied through to the host. The only extra bit is that the actual command that gets run is printed out on stderr before it does get run. For example:
We could provide something like this in the created toolbox container. I'm still polishing this up a bit. One thing that doesn't work yet that we should think about is what to do if the user wanted to execute the command on the host as sudo. |
I tried to duplicate this, but I just placed [user@toolbox ~] podman ps
+ exec flatpak-spawn --host podman ps
+ exec flatpak-spawn --host podman ps
/var/home/user/.local/bin/podman: line 4: exec: flatpak-spawn: not found Of course since Anyways I solved it by changing
EDIT: This causes a few other problems. For example |
Using #!/bin/sh
set -o errexit
set -o nounset
executable="$(basename "$0")"
if [ "$(basename "$(realpath "$0")")" = "${executable}" ]; then
echo "can't run ${executable} via ${executable}" >&2
exit 1
fi
# This seems like the best way to detect if we're inside a toolbox container.
if [ -n "${TOOLBOX_PATH:-}" ]; then
set -x
exec flatpak-spawn --host "${executable}" "$@"
fi
# Otherwise do a little dance to find the executable that would have run if not
# for $0 being on the path, and run that instead.
executable="$(
# Remove this script's directory from PATH; this assumes that you'll never want
# to run a sibling via this script.
dir="$(dirname "$0")"
PATH="$(echo "${PATH}" | sed "s+:${dir}:++")"
PATH="$(echo "${PATH}" | sed "s+${dir}:++")"
PATH="$(echo "${PATH}" | sed "s+:${dir}++")"
command -v "${executable}"
)"
exec "${executable}" "$@" (This hasn't been tested this in weird nested execution cases, though I think it should work.) *assumes |
Another option could be to make podman within the container always use |
Loosely based off containers/toolbox#145 Doesn't work with sudo and hard coded shims in the docker container. Pending better UIX with containers/toolbox#553 Signed-off-by: anthr76 <[email protected]>
Can you please elaborate why flatpak cannot be used inside OCI container? It seems sad if you cannot build new version of flatpak and keep its possibly different runtime deps inside your toolbox but need to somehow hack them to your host. |
#1072 created specifically about potentially pursuing that. |
I did create following files: #!/bin/bash
executable=$(basename $0)
exec flatpak-spawn --host "${executable}" "$@"
#!/bin/bash
executable=$(basename $0)
exec toolbox run "${executable}" "$@" Example for sudo ln -s /usr/bin/podman /usr/local/bin/docker
sudo ln -s ~/.local/shims/toolbox-run /usr/local/bin/docker-compose Toolbox symlinks: sudo ln -s ~/.local/shims/flatpak-spawn-host /usr/local/bin/podman
sudo ln -s ~/.local/shims/flatpak-spawn-host /usr/local/bin/docker |
Hey guys, Another solution for those who:
Edit your .bashrc, that is normally loaded when you open a toolbox:
|
@lp35 Thank you for this!!! I love it. For anyone else trying this code, it needs a tweak.
|
Various commands like
flatpak
,podman
,rpm-ostree
etc. can't really be used inside an OCI container. Some of them, likepodman
, might have some limited use, but, by and large, people expect to run them directly on the host.At the same time, we expect a good percentage of users of the command line interface to spend most of their time inside a toolbox container, and one of the goals of the Toolbox project is to reduce the cognitive burden of using mutable containers on locked-down and immutable host OSes like Silverblue. Commands like
flatpak
andrpm-ostree
are important tools for interfacing with such OSes.Therefore, it would be nice if we could provide a user experience that's better than having to switch back and forth between a host and toolbox shell, or having to prefix every command with things like
flatpak-spawn --host
.The easiest option is to install aliases in the shell running inside the container. However, it doesn't give us things like manuals and shell completion.
Another option is to pre-install the
flatpak
,podman
,rpm-ostree
, etc. RPMs in thefedora-toolbox
base images but remove all the code, leaving behind only the manuals and shell completion. Then thetoolbox
command can place the corresponding shims via bind mounts to forward the calls to the host when starting the toolbox containers.This will ensure that the
fedora-toolbox
images don't get bigger with useless Go binaries, and the wrappers can be kept updated through thetoolbox
package on the host. One advantage of having explicit shims over aliases is that we can intercept those corner cases where command invocations can't be forwarded to the host. eg., they might involve a path that's not shared between the host and the container. Failing with a clear error message is better than an obscure failure or strange side-effects.However, I don't know what will happen if one of these packages are updated inside the containers. Would they interfere with the bind mounted shims? It would be nice if we could trim the useless bits from those packages during or after updating the RPM.
The text was updated successfully, but these errors were encountered: