Skip to content
aaronpsPublic

About

Persistent Linux servers in containers

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

vesselbox

Persistent Linux servers in containers.

Run a full Linux distro inside a container, connect over SSH, and use it like a remote VPS: systemd boots and installed packages persist across restarts.

Note

vesselbox is in pre-release development. You are welcome to test it and share feedback.

Architecture

One container, two layers. The bootstrap stays container PID 1, builds the tenant's environment, and spawns its entrypoint with dropped capabilities as PID 1 of the nested namespace:

---
config:
  layout: elk
---
flowchart LR
    admin ~~~ container ~~~ out_tenant

    exec_admin --> container
    exec_tenant --> tenant

    ssh --> tenant
    http --> tenant
    other --> tenant

    subgraph admin[Admin user]
      exec_admin(["exec bash/sh"])
      exec_tenant(["exec vesselbox-tenant"])
    end

    subgraph container["Container · Admin (CAP_SYS_ADMIN · seccomp · read-only)"]

        supervisor["vesselbox-init (Supervisor)"]

        subgraph tenant["Tenant · Isolated Namespace · Dropped Caps"]
            systemd["systemd (PID 1)"]
            sshd
            user_services["User Services"]
            ai_agents["AI Agents"]
        end

        storage[("Persistent Volume")]

        supervisor --> tenant

        systemd --> sshd
        systemd --> user_services
        systemd --> ai_agents

        storage --- tenant
        
    end

    subgraph out_tenant[External User]
      ssh([ssh])
      http([http])
      other([other])
    end
Loading

Build

1. Build the vesselbox image

docker buildx build . -f docker/vesselbox/Dockerfile -t vesselbox/vesselbox:latest

2. Build an environment image

NOTE: Using the docker output might require a custom builder in older docker versions, for example creating it with docker buildx create --name custom --driver=docker-container and using it by adding the argument --builder=custom where custom is the name you decide.

Example for Ubuntu 24.04, saved to dist/ubuntu24.04.docker.tar:

docker buildx build \
    --output type=docker,dest=dist/ubuntu24.04.docker.tar,compression=gzip \
    -t vesselbox/ubuntu:24.04 \
    --progress=plain \
    docker/ubuntu24.04

Other buildx output examples:

  • push to a container registry as an image, depends if you use a custom builder or the default:

    • default builder: --output type=registry,name=localhost:5000/vesselbox/ubuntu:24.04,compression=gzip
    • custom builder: --output type=registry,registry.insecure=true,name=host.docker.internal:5000/vesselbox/ubuntu:24.04,compression=gzip
  • to a rootfs file: --output type=tar,dest=dist/ubuntu24.04.rootfs.tar

Building environment images supports some customizations, check the Dockerfiles.

Use

Using docker compose

compose.yaml has the examples.

vesselbox-service.yaml defines the common vesselbox service, inherit from it or vesselbox-from-dist helper (mounts ./dist on /images) for smaller service definitions. Set the hostname to the same name as your service:

Minimal compose.yaml:

volumes:
  # we will use `mybox` volume name
  mybox:

services:
  # your service name
  mybox:

    # use the same name as the hostname
    hostname: mybox

    extends:
      file: vesselbox-service.yaml
      service: vesselbox
  
    environment:
      # options for vesselbox-setup
      - VESSELBOX_SETUP=--registry=registry:5000/vesselbox/ubuntu:26.04 --insecure
      # this is for systemd
      - VESSELBOX_SIGNAL=SIGRTMIN+3

    # forward at least port 22 for ssh.
    ports:
      - 12345:22

    volumes:
      # mount mybox volume in /tenant
      - type: volume
        source: mybox
        target: /tenant
  1. When the environment is new, initialize it:

    docker compose run --rm --entrypoint vesselbox-setup mybox init

    If is not now, ensure it is stopped then reinitialize it with:

    docker compose run --rm --entrypoint vesselbox-setup mybox reinit
  2. Start it as a service:

    docker compose up -d mybox

    Alternatively you could run it directly, for one-of tests, and you can login directly without ssh:

    docker compose run --rm -P mybox

    You can also run an environment without starting systemd:

    docker compose run --rm mybox cat /etc/os-release
  3. You can connect to it using ssh to your forwarded port using localhost or the real machine IP if it is remote:

    ssh -p 12345 root@localhost

    You can enter the environment directly for administration

    docker compose exec mybox vesselbox-tenant

    Note that you can run any service in it, for example mysql/mariadb, then forward the port and connect to it like you would.

    If you add more ports later just run this command and the box will restart:

    docker compose up -d mybox
  4. These services are configured to restart always, you can use shutdown or halt within them and they will restart after gracefully exiting. To stop them for good use:

    # stop and remove the container, data is safe in the volume.
    docker compose down mybox
    
    # stop and keep the container,
    docker compose stop mybox

    IMPORTANT: Do not run docker compose down -v unless you want to also delete all the data in the vesselboxes.

Using docker

Use scripts/create-vesselbox.sh to create an environment, the initial root password will be asked on creation.

scripts/create-vesselbox.sh mybox dist/ubuntu24.04.docker.tar --port 2222:22 --systemd --restart
  • mybox is the volume, the container and the hostname of the environment.
  • --port HOST:CONTAINER forwards ports and may be repeated.
  • --restart creates the container with --restart always.
  • --systemd use this when the environment uses systemd.
  • --signal VALUE sends a custom signal to stop the environment.

After the environment is created, start it with docker start mybox, on this example, connect to port 2222.

Known limitations (needs review/recheck)

  • containerd/docker/podman won't run inside vesselbox environments.
  • Units using PrivateUsers= do not work, because creating a user namespace is blocked.
  • If a deployment needs a filesystem mounted (for example an NFS volume), the operator/admin has to mount it externally, you cannot mount things in these environments.
  • docker exec/kubectl exec are operator actions and have higher capabilities.
  • no dmesg for thee.

TODO

  • maybe is time to move the Dockerfiles shared files somewhere shared, like "drop-ins".
  • vesselbox-setup: read the image's OCI config (env, workdir, user, entrypoint+cmd, VOLUME dirs), store it as the volume's default command; maybe a script setting env vars, mkdir volumes and running entrypoint+cmd on workdir.
  • when entering the admin environment, the prompt should have some kind of information detailing this, sometimes the prompt of the admin and the tenant is undistinguisable, just a little bit of QOL.
  • /etc/{hosts,hostname,resolv.conf} are tenant managed they could do some tricks with links, needs review.
  • now not using pivot_root, seccomp needs review
  • remove the PermitRootLogin from vesselbox-setup, is a remnant of an old version
  • Create the vesselbox utility script: a single tool to replace entrypoint, vesselbox-setup and other subcommands.
  • nvidia gpu
  • create examples of uses: database services, nginx, redis/valkey, ai agents(openclown OpenClaw,Messmer Hermes Agent, etc)
  • Helm chart / raw manifests
  • Consider a note about --oom-score-adj for important containers.

About

Persistent Linux servers in containers

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages