favicon here hometagsblogmicrobio cvtech cvgpg keys

Calling Executables Outside Distrobox That Are From Another Distrobox

#container #distrobox #podman

Soc Virnyl Estela | 2023-08-06 | updated: 2024-01-30 |reading time: ~3min

Update§

This old post is outdated and requires a small update. To run an executable from another container (here we use distrobox, a frontend for podman or docker), you just need to run this command inside the desired container where you want to run the executable.

sudo ln /usr/bin/distrobox-host-exec /usr/local/bin/my-executable

Make sure that the my-executable was already distrobox-exported to the host.

Old post§

To anyone that might have asked themselves

How do I call an executable from Y distro to the current X distro I am using in distrobox?

The answer is to create a script. But first you will have to use distrobox-host-exec. Create a symlink inside your distrobox. You can either declare an init-hook or do it manually. The command is

ln -sf distrobox-host-exec /usr/local/bin/podman

This will create a pseudo podman executable that will run the host system's podman, assuming you have that installed in your host system.

To check if it works, run

podman ps

This will give you a list of available containers that are active.

Example situation§

So let's assume you are in a weird situation. You want to use zig but the one on openSUSE Tumbleweed distrobox is 0.10.0 because it has an issue with glibc versions. But it builds correctly on openSUSE Leap 15.5! The next thing you did was to create your leap distrobox

distrobox-create -i leap:latest -n leap

And then you ran the following command inside your leap distrobox

sudo zypper addrepo https://download.opensuse.org/repositories/devel:tools:compiler/15.5/devel:tools:compiler.repo
sudo zypper refresh
sudo zypper install zig

So uh... how do I use zig from leap when I am in a tumbleweed distrobox?

By using distrobox-host-exec which calls your podman executable! Remember the symlink? Here is the idea

podman has an exec command. Running podman exec --help gives you the following output:

Run a process in a running container

Description:
  Execute the specified command inside a running container.


Usage:
  podman exec [options] CONTAINER [COMMAND [ARG...]]

Examples:
  podman exec -it ctrID ls
  podman exec -it -w /tmp myCtr pwd
  podman exec --user root ctrID ls

Options:
  -d, --detach               Run the exec session in detached mode (backgrounded)
      --detach-keys string   Select the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _ (default "ctrl-p,ctrl-q")
  -e, --env stringArray      Set environment variables
      --env-file strings     Read in a file of environment variables
  -i, --interactive          Keep STDIN open even if not attached
  -l, --latest               Act on the latest container podman is aware of
                             Not supported with the "--remote" flag
      --preserve-fds uint    Pass N additional file descriptors to the container
      --privileged           Give the process extended Linux capabilities inside the container.  The default is false
  -t, --tty                  Allocate a pseudo-TTY. The default is false
  -u, --user string          Sets the username or UID used and optionally the groupname or GID for the specified command
  -w, --workdir string       Working directory inside the container

Since it says here that we can run a process from a running container, we can create a script to run zig in your tumbleweed distrobox!

#!/bin/bash
/usr/local/bin/podman exec --user $USER -it -w $PWD leap zig $@

And save it to /usr/local/bin/zig and run sudo chmod +x /usr/local/bin/zig.

Testing your zig executable§

Inside your tumbleweed distrobox which now contains your pseudo zig executable, you can test if it works by doing the commands

md hello-zig/
cd $_
zig init-exe
zig build
./zig-out/hello-zig

The last command should output

All your codebase are belong to us.
Run `zig build test` to run the tests.

How it works§

We have distrobox-host-exec (which calls host-spawn in the background), and podman. By using distrobox-host-exec to run the host system podman, we can also check other running containers, not just from leap distrobox in the previous examples.

With podman, we can use its exec command to run executables from other containers. The important flags are

  • -w or --workdir. This is where you set $PWD
  • -i or --interactive. This allows interactivity
  • -t or --tty. This will allow it to work somewhat okay-ish in a terminal.

Plus $@ to add possible other subcommands of an executable e.g. build, test, --help.

The --user is set to $USER so it respects your user inside the container. Otherwise, it will become root which maybe is not what you want.

So the final and cool command for the pseudo zig executable is:

#!/bin/bash

# leap can be anything: container ID or container NAME
/usr/local/bin/podman exec --user $USER -it -w $PWD leap zig $@

More information§

You can find more information from the following links:

Articles from blogs I follow around the net

Body::poll_progress

This describes a proposal for a cancelation problem with hyper’s request and response bodies. hyper is an HTTP library for the Rust language. Background: what is the Body trait? The Body trait used by hyper is meant to represent a potentially streaming (…

via seanmonstarApril 22, 2025

CVE-2025-32433 - State Machine Err-ly RCE in Erlang/OTP SSH Server

CVE-2025-32433 is a remote code execution vulnerability in the SSH server implementation within Erlang’s OTP libraries (affecting versions legendary CVSS score of 10.0 and became known as a vulnerability for which AI-assisted exploit development process wa…

via GreyNoise LabsApril 22, 2025

AI-powered search summaries led to less clicks to websites

Google claims that links beside AI summaries get more clicks. This goes against intuition. Ahrefs did some analysis on this recently. Who is right?

via Rob O'Leary | BlogApril 21, 2025

Resistance from the tech sector

As of late, most of us have been reading the news with a sense of anxious trepidation. At least, those of us who read from a position of relative comfort and privilege. Many more read the news with fear. Some of us are already no longer in a position to re…

via Drew DeVault's blogApril 20, 2025

Retrospective: Five Years Blogging About Cryptography as a Gay Furry Online

The history of this blog might very well be a cautionary tail (sic) about scope creep. The Original Vision For Dhole Moments Originally, I just wanted a place to write about things too long for Twitter (back when I was an avid Twitter poster). I also figur…

via Dhole MomentsApril 17, 2025

Status update, April 2025

Hi! Last week wlroots 0.19.0-rc1 has been released! It includes the new color management protocol, however it doesn’t include HDR10 support because the renderer and backend bits haven’t yet been merged. Also worth noting is full explicit synchronization su…

via emersionApril 16, 2025

The IndieWeb & that blog roll

The IndieWeb's something I've known about for a while, but never really engaged with. I mean this is very much part of The Indie Web, the very thing, you're reading it right now. But in terms of the camel cased movement, not so much. To me they seemed a bi…

via Mike KreuzerApril 16, 2025

Tidbyt without the company

Remember the Tidbyt? It’s a super low-resolution, internet-connected, wood-paneled display that I wrote a review of it back in 2022. It’s been on my shelf for years now, showing the time, weather, warning me when the UV is going to be high. In 2023 I used …

via macwright.comApril 12, 2025

One does not simply write a SSH config parser (in Rust)

Do you know the feeling when you start a project and you think it will be easy, but then you realize that it is not? This is the story of the implementation of ssh2-config, a Rust library to parse SSH config files. Why did I write this? Because basically…

via Christian Visintin BlogMarch 30, 2025

LLDB's TypeSystems: An Unfinished Interface

Well, it's "done". TypeSystemRust has a (semi) working prototype for LLDB 19.x. It doesn't support expressions or MSVC targets (i.e. PDB debug info), and there are a whole host of catastrophic crashes, but it more or less proves what it needs to: Rust's de…

via Cracking the ShellMarch 28, 2025

Backup Yubikey Strategy

After a local security meetup where I presented about Webauthn, I had a really interesting chat with a member about a possible Yubikey management strategy. Normally when you purchase a yubikey it's recommended that you buy two of them - one primary and one…

via Firstyear's blog-a-logFebruary 28, 2025

Ludic's Guide To Getting Software Engineering Jobs

The steps in this guide have generated A$1,179,000 in salary (updated 13th April, 2025), measured as the sum of the highest annual salaries friends and readers have reached after following along, where they were willing to attribute their success actions i…

via LudicityFebruary 28, 2025

The Adrian Dittmann Story

the evidence, from A to Z, and righting the wrongs

via maia blogJanuary 05, 2025

Awesome Fish functions

Some awesome fish functions that I have accumalated over the years.

via Ishan WritesJanuary 03, 2025

Physics Simulations in Bevy

Bevy is the most popular and powerful game engine in Rust. Because of its flexibility, it can be used not only for games but also for (scientific) physics simulations. In this blog post, I will share my experience using Bevy for physics simulations from sc…

via mo8it.comJuly 19, 2024

Defending myself against defensive writing

I write this blog because I enjoy writing. Some people enjoy reading what I write, which makes me feel really great! Recently, I took down a post and stopped writing for a few months because I didn't love the reaction I was getting on social media sites li…

via pcloadletterMay 27, 2024

The Elegiac Hindsight of Intelligent Machines

This essay was edited out of a chapter of my book, The Intelligence Illusion: a practical guide to the business risks of Generative AI, with minor alterations. “See the choice of dreams”, and then worry about it Very well. This book – this side, Dream …

via Out of the Software Crisis (Newsletter)October 13, 2023

Regex engine internals as a library

Over the last several years, I’ve rewritten Rust’s regex crate to enable better internal composition, and to make it easier to add optimizations while maintaining correctness. In the course of this rewrite I created a new crate, regex-automata, which expos…

via Andrew Gallant's Blog on Andrew Gallant's BlogJuly 05, 2023

Generated by openring-rs

favicon here hometagsblogmicrobio cvtech cvgpg keys