distrobox - 在终端内使用任何 Linux 发行版。实现软件的向后和向前兼容性,并自由使用您更喜欢的任何发行版。

Created at: 2021-11-18 23:41:03
Language: Shell
License: GPL-3.0

外套箱

以前的徽标信用 J4ckr3D
当前徽标信用 David Lapshin

皮棉 词 GitHub GitHub 发布(按日期最新) 包装状态 Github问题需要帮助 GitHub 按标签发布

使用终端内的任何 Linux 发行版。实现与软件的向后和向前兼容性,并自由使用你更熟悉的任何发行版。Distrobox 使用 ,或者使用你选择的 Linux 发行版创建容器。创建的容器将与主机紧密集成,允许共享用户的HOME目录,外部存储,外部USB设备和图形应用程序(X11 / Wayland)以及音频。

podman
docker
lilipod


文档 - 矩阵室 - 电报组


概述



What it does

Simply put it's a fancy wrapper around , or to create and start containers highly integrated with the hosts.

podman
docker
lilipod

The distrobox environment is based on an OCI image. This image is used to create a container that seamlessly integrates with the rest of the operating system by providing access to the user's home directory, the Wayland and X11 sockets, networking, removable devices (like USB sticks), systemd journal, SSH agent, D-Bus, ulimits, /dev and the udev database, etc...

It implements the same concepts introduced by https://github.com/containers/toolbox but in a simplified way using POSIX sh and aiming at broader compatibility.

All the props go to them as they had the great idea to implement this stuff.

It is divided into 12 commands:

  • distrobox-assemble
    - creates and destroy containers based on a config file
  • distrobox-create
    - creates the container
  • distrobox-enter
    - to enter the container
  • distrobox-ephemeral
    - create a temporal container, destroy it when exiting the shell
  • distrobox-list
    - to list containers created with distrobox
  • distrobox-rm
    - to delete a container created with distrobox
  • distrobox-stop
    - to stop a running container created with distrobox
  • distrobox-upgrade
    - to upgrade one or more running containers created with distrobox at once
  • distrobox-generate-entry
    - to create an entry of a created container in the applications list
  • distrobox-init
    - the entrypoint of the container (not meant to be used manually)
  • distrobox-export
    - it is meant to be used inside the container, useful to export apps and services from the container to the host
  • distrobox-host-exec
    - to run commands/programs from the host, while inside of the container

It also includes a little wrapper to launch commands with instead of calling the single files.

distrobox COMMAND

Please check the usage docs here and see some handy tips on how to use it

See it in action

Thanks to castrojo, you can see Distrobox in action in this explanatory video on his setup with Distrobox, Toolbx, Fedora Silverblue for the uBlue project (check it out!)

Video

Why

  • Provide a mutable environment on an immutable OS, like Endless OS, Fedora Silverblue, OpenSUSE MicroOS, ChromeOS or SteamOS3
  • Provide a locally privileged environment for sudoless setups (eg. company-provided laptops, security reasons, etc...)
  • To mix and match a stable base system (eg. Debian Stable, Ubuntu LTS, RedHat) with a bleeding-edge environment for development or gaming (eg. Arch, OpenSUSE Tumbleweed or Fedora with latest Mesa)
  • Leverage high abundance of curated distro images for docker/podman to manage multiple environments

Refer to the compatibility list for an overview of supported host's distro HERE and container's distro HERE.

Aims

This project aims to bring any distro userland to any other distro supporting podman, docker or lilipod. It has been written in POSIX sh to be as portable as possible and not have problems with dependencies and glibc version's compatibility.

Refer HERE for a list of supported container managers and minimum supported versions.

It also aims to enter the container as fast as possible, every millisecond adds up if you use the container as your default environment for your terminal:

These are some sample results of on the same container on my weak laptop:

distrobox-enter

~$ hyperfine --warmup 3 --runs 100 "distrobox enter bench -- whoami"
Benchmark 1: distrobox enter bench -- whoami
  Time (mean ± σ):     395.6 ms ±  10.5 ms    [User: 167.4 ms, System: 62.4 ms]
  Range (min … max):   297.3 ms … 408.9 ms    100 runs

安全隐患

隔离和沙盒不是该项目的主要目标,相反,它旨在将容器与主机紧密集成。容器将完全访问你的家、笔式驱动器等,因此不要指望它像普通的 docker/podman 容器或 flatpak 那样高度沙盒化。

⚠️ 小心⚠️如果你使用 docker,或者你使用 podman/lilipod 和标志,容器将以 root 身份运行,所以 root 容器内的 root 可以修改容器外的系统内容,还要注意,在 root 模式下,系统会要求你设置用户的密码,这将确保至少容器不是 root 的无密码门, 但是,如果你对此有安全问题,请使用以无根模式运行的 podman 或 lilipod。Rootless docker 仍然没有按预期工作,将来完成时会包含在内。

--root/-r

也就是说,它正在实现与主机的某种解耦,如下所述: #28 沙盒模式


快速入门

创建一个新的外装箱:

distrobox create -n test

使用 Systemd 创建一个新的发行版(类似于 LXC):

distrobox create --name test --init --image debian:latest --additional-packages "systemd libpam-systemd"

输入创建的发行版:

distrobox enter test

添加一个具有不同发行版的发行版,例如 Ubuntu 20.04:

distrobox create -i ubuntu:20.04

在发行版中执行命令:

distrobox enter test -- command-to-execute

列出正在运行的发行版:

distrobox list

停止正在运行的发行版:

distrobox stop test

删除外箱:

distrobox rm test

你可以查看 这里 了解更多高级用法,并查看有用的提示的完整列表 这里

组装外箱

清单文件可用于声明一组发行版,并用于批量创建/销毁它们。

distrobox-assemble

查看distrobox-assemble的使用文档以获取更详细的指南。

配置发行版

配置文件可以放置在以下路径中,从最不重要到最重要的路径:

  • /usr/share/distrobox/distrobox.conf
  • /usr/etc/distrobox/distrobox.conf
  • /etc/distrobox/distrobox.conf
  • ${HOME}/.config/distrobox/distrobox.conf
  • ${HOME}/.distroboxrc

你可以指定内部发行版配置和特定于发行版箱的环境变量。

示例配置文件:

container_always_pull="1"
container_generate_entry=0
container_manager="docker"
container_image_default="registry.opensuse.org/opensuse/toolbox:latest"
container_name_default="test-name-1"
container_user_custom_home="$HOME/.local/share/container-home-test"
container_init_hook="~/.local/distrobox/a_custom_default_init_hook.sh"
container_pre_init_hook="~/a_custom_default_pre_init_hook.sh"
container_manager_additional_flags="--env-file /path/to/file --custom-flag"
container_additional_volumes="/example:/example1 /example2:/example3:ro"
non_interactive="1"
skip_workdir="0"
PATH="$PATH:/path/to/custom/podman"

Alternatively it is possible to specify preferences using ENV variables:

  • DBX_CONTAINER_ALWAYS_PULL
  • DBX_CONTAINER_CUSTOM_HOME
  • DBX_CONTAINER_IMAGE
  • DBX_CONTAINER_MANAGER
  • DBX_CONTAINER_NAME
  • DBX_CONTAINER_ENTRY
  • DBX_NON_INTERACTIVE
  • DBX_SKIP_WORKDIR

Installation

Distrobox is packaged in the following distributions, if your distribution is on this list, you can refer to your repos for installation:

包装状态

Thanks to the maintainers for their work: M0Rf30, alcir, dfaggioli, AtilaSaraiva, michel-slm

Alternative methods

Here is a list of alternative ways to install distrobox

Curl or Wget

If you like to live your life dangerously, or you want the latest release, you can trust me and simply run this in your terminal:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh
# or using wget
wget -qO- https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh

or if you want to select a custom directory to install without sudo:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --prefix ~/.local
# or using wget
wget -qO- https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --prefix ~/.local

If you want to install the last development version, directly from last commit on git, you can use:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh -s -- --next
# or using wget
wget -qO- https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh -s -- --next

or:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --next --prefix ~/.local
# or using wget
wget -qO- https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --next --prefix ~/.local

Warning Remember to add prefix-path-you-choose/bin to your PATH, to make it work.

Git

Alternatively you can clone the project using

git clone
or using the latest release HERE.

Enter the directory and run

./install
, by default it will attempt to install in
~/.local
but if you run the script as root, it will default to
/usr/local
. You can specify a custom directory with the
--prefix
flag such as
./install --prefix ~/.distrobox
.

Prefix explained: main distrobox files get installed to

${prefix}/bin
whereas the manpages get installed to
${prefix}/share/man
.


Check the Host Distros compatibility list for distro-specific instructions.

Dependencies

Distrobox depends on a container manager to work, you can choose to install either podman, docker or lilipod.

Please look in the Compatibility Table for your distribution notes.

There are ways to install Podman without root privileges and in home. or Lilipod without root privileges and in home. This should play well with completely sudoless setups and with devices like the Steam Deck (SteamOS).


Uninstallation

If you installed distrobox using the

install
script in the default install directory use this:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/uninstall | sudo sh

or if you specified a custom path:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/uninstall | sh -s -- --prefix ~/.local

Else if cloned the project using

git clone
or using the latest archive release from HERE,

enter the directory and run

./uninstall
, by default it will assume the install directory was
/usr/local
if ran as root or
~/.local
, you can specify another directory if needed with
./uninstall --prefix ~/.local


发行版盒

This artwork uses Cardboard Box model by J0Y licensed under Creative Commons Attribution 4.0
This artwork uses GTK Loop Animation by GNOME Project licensed under Creative Commons Attribution-ShareAlike 3.0 as a pre-configured scene