Skip to content

feat: add vers docker run command to execute Dockerfiles on Vers VMs#159

Draft
yevbar wants to merge 4 commits intomainfrom
yb/docker
Draft

feat: add vers docker run command to execute Dockerfiles on Vers VMs#159
yevbar wants to merge 4 commits intomainfrom
yb/docker

Conversation

@yevbar
Copy link
Contributor

@yevbar yevbar commented Feb 23, 2026

Summary

Adds a new vers docker command group that allows running Dockerfiles on Vers VMs instead of containers.

New Commands

  • vers docker run [dockerfile] - Parse and execute a Dockerfile on a Vers VM
  • vers docker build [context] - Build a Dockerfile as a Vers snapshot (commit)
  • vers docker compose up - Start a compose project with each service as a VM

Deprecation Notice

⚠️ vers build --dockerfile is now deprecated in favor of vers docker build.

The old command still works but will show a deprecation warning:

$ vers build --dockerfile ./Dockerfile
Flag --dockerfile has been deprecated, use 'vers docker build -f <dockerfile>' instead
⚠️  DEPRECATED: 'vers build --dockerfile' is deprecated. Use 'vers docker build' instead.

Migration: Replace vers build --dockerfile ./Dockerfile with vers docker build -f ./Dockerfile .

Features

Dockerfile Parsing

  • Parses standard Dockerfile instructions: FROM, RUN, COPY, ADD, WORKDIR, ENV, EXPOSE, CMD, ENTRYPOINT
  • Handles JSON array format ["cmd", "arg"] and shell format
  • Supports line continuations with \
  • Multi-stage build support (uses final stage)

Execution

  • Creates a new Vers VM with configurable resources
  • Copies build context to the VM via SFTP (respects COPY instructions)
  • Executes RUN commands sequentially over SSH
  • Sets up environment variables from ENV instructions
  • Starts the application (CMD/ENTRYPOINT)

Flags

  • -d, --detach - Run in background mode
  • -i, --interactive - Run with TTY support
  • -c, --context - Custom build context directory
  • -N, --name - Set VM alias
  • -e, --env - Pass additional environment variables
  • --mem - Memory size in MiB (default: 1024)
  • --vcpu - Number of vCPUs (default: 2)
  • --fs-size - Filesystem size in MiB (default: 4096)

Usage Examples

# Build a Dockerfile as a Vers snapshot
vers docker build .
vers docker build -t myapp:latest .
vers docker build -f Dockerfile.prod .

# Run Dockerfile in current directory
vers docker run

# Run specific Dockerfile with custom context
vers docker run -c ./app ./Dockerfile

# Run in detached mode with alias
vers docker run -d -N myapp ./Dockerfile

# Run with custom resources
vers docker run --mem 2048 --vcpu 4 ./Dockerfile

Benefits over Docker

The VM persists after completion, enabling:

  • vers connect <vm> - SSH into the environment
  • vers commit <vm> - Create a snapshot
  • vers branch <vm> - Branch the state
  • vers tunnel <vm> <port> - Forward ports

Testing

  • Added comprehensive unit tests for Dockerfile parser
  • All existing tests pass

Files Changed

  • cmd/docker.go - CLI command definitions
  • cmd/build.go - Added deprecation for --dockerfile flag
  • internal/docker/parser.go - Dockerfile parser
  • internal/docker/parser_test.go - Parser tests
  • internal/docker/executor.go - Dockerfile executor
  • internal/handlers/docker_run.go - Handler logic
  • internal/handlers/docker_build.go - Build handler logic
  • internal/presenters/docker_presenter.go - Output formatting

Adds a new 'vers docker' command group with 'vers docker run' subcommand that:
- Parses Dockerfiles and extracts instructions (FROM, RUN, COPY, WORKDIR, ENV, EXPOSE, CMD, ENTRYPOINT)
- Creates a new Vers VM with configurable resources
- Copies build context to the VM via SFTP
- Executes RUN commands over SSH
- Starts the application (CMD/ENTRYPOINT)

Features:
- Detached mode (-d) for background execution
- Interactive mode (-i) for TTY support
- Custom build context (-c)
- VM aliasing (-N)
- Environment variable passthrough (-e)
- Configurable VM resources (--mem, --vcpu, --fs-size)

This enables Docker-like workflows with Vers VM benefits:
- Persistent state with snapshots
- Branch and restore capabilities
- Full SSH access
- No container overhead
@yevbar yevbar marked this pull request as draft February 23, 2026 21:24
Extends Docker CLI compatibility with:

docker build:
- vers docker build -t myapp .
- vers docker build -f Dockerfile.prod .
- Creates a Vers commit (snapshot) from a Dockerfile
- Cleans up build VM after commit

docker compose up:
- vers docker compose up
- vers docker compose up -d
- vers docker compose up web api
- Parses docker-compose.yml files
- Creates one Vers VM per service
- Handles dependency ordering (topological sort)
- Sets up inter-service environment variables

This follows the pattern of 'uv pip' and 'jj git' - providing familiar
CLI compatibility on top of a different underlying system.
- 'vers build --dockerfile' now delegates to 'vers docker build' handler
- Shows deprecation warning when --dockerfile flag is used
- Flag is marked deprecated and hidden from help output
- Both commands now use the same underlying DockerBuildReq handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant