You are viewing the arm version of our documentation.

Accessing your VM

Various ways to access your VM

Prerequisites

  1. You’ve installed the Anka Virtualization package
  2. You’ve created and prepared your first VM Template
When running Anka commands on your machine, ensure that you have an active login session and have enabled automatic login for the current user: System Preferences > Users > Enable automatic login for the host. You might have to VNC in to the host machine if you’re connected over SSH.

Anka Run (exec)

Requires that addons are installed inside of the VM.

Similar to docker exec, anka run allows execution of commands inside of a VM.

> anka run --help
usage: run [options] vmid

   Run a command inside of a VM (will start VM if suspended or stopped

options:
  -D,-w,--workdir <val>    Working directory inside the VM
  -v,--volume <val>        Mount a host directory into VM
  -n,--no-volume           Use this flag to prevent implicit mounting of current folder (see --volume option)
  -E                       Inherit the entire environment in non-overriding mode
  -e <val>                 Provide an environment variable in overriding mode
  -f,--env-file <val>      Provide environment variables from file
  -Q,--quiet               Suppress the stdout from the command
  -b,--background          Run the command in background returning PID to wait with 'wait [PID...]' command
If the VM is in a stopped state, anka run will automatically start it.

You can use anka run on the host terminal to validate things are working properly:

❯ anka run 12.0-beta bash -c "hostname && ls -l && ping -c 5 google.com"
12-0-beta.local
total 0
drwx------+  3 anka  staff    96 Oct 14 09:35 Desktop
drwx------+  3 anka  staff    96 Oct 14 09:35 Documents
drwx------+  3 anka  staff    96 Oct 14 09:35 Downloads
drwx------@ 74 anka  staff  2368 Oct 19 11:31 Library
drwx------   4 anka  staff   128 Oct 19 11:14 Movies
drwx------+  3 anka  staff    96 Oct 14 09:35 Music
drwx------+  3 anka  staff    96 Oct 14 09:35 Pictures
drwxr-xr-x+  4 anka  staff   128 Oct 14 09:35 Public
PING google.com (142.251.35.174): 56 data bytes
64 bytes from 142.251.35.174: icmp_seq=0 ttl=108 time=10.316 ms
64 bytes from 142.251.35.174: icmp_seq=1 ttl=108 time=10.270 ms
64 bytes from 142.251.35.174: icmp_seq=2 ttl=108 time=10.163 ms
64 bytes from 142.251.35.174: icmp_seq=3 ttl=108 time=10.305 ms
64 bytes from 142.251.35.174: icmp_seq=4 ttl=108 time=10.281 ms

--- google.com ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 10.163/10.267/10.316/0.055 ms

The anka run command doesn’t source .profile, .bash_profile, or .zshrc by default. You have to source the file before executing other commands.

❯ anka run 12.0-beta bash -c "env | grep INSIDE"

❯ anka run 12.0-beta bash -c "source ~/.zshrc; env | grep INSIDE"
INSIDE_ZSHRC=true
To inherit the host’s environment, use the anka run -E (existing VM variables will not be overridden by host’s variables) or -e MYENV options. You can also pass them inside of a file like anka run --env-file environment.txt, where environment.txt is a text file in the form VARIABLE=VALUE, one variable per line.
An advanced usage example of anka run inside of a bash script can be found in our Getting Started Repo’s Tag Creation Script.

Anka View

The anka viewer requires an active UI session on the host.
The anka view command currently will only function if you at some point started the VM with anka start -uv.
> anka view --help
usage: view [options] vmid

   Open VM display

options:
  -d,--display <val>       Specify the display(s) to view
  -s,--screenshot          Take PNG screenshot
  --click                  Send HDI events
  --click-rec              Record HID events
  -o,--output <val>        Specify output file for the view operations

SSH

❯ anka modify 12.0.1 add port --guest-port 22 ssh

❯ anka show 12.0.1 network
+------------+------------+
| mode       | shared     |
+------------+------------+
| controller | virtio-net |
+------------+------------+

port_forwarding_rules:
+------+----------+------------+
| name | protocol | guest_port |
+------+----------+------------+
| SSH  | tcp      | 22         |
+------+----------+------------+

❯ anka start 12.0.1

❯ anka show 12.0.1 network
+------------+-------------------+
| mode       | shared            |
+------------+-------------------+
| controller | virtio-net        |
+------------+-------------------+
| mac        | 52:74:36:66:42:d7 |
+------------+-------------------+

port_forwarding_rules:
+------+----------+---------+------------+-----------+
| name | protocol | host_ip | guest_port | host_port |
+------+----------+---------+------------+-----------+
| SSH  | tcp      | 0.0.0.0 | 22         | 10000     |
+------+----------+---------+------------+-----------+

❯ ssh anka@localhost -p 10000
Password:
Last login: Mon Apr  6 12:45:50 2020
Mac-mini:~ anka

VNC

Once you’ve enabled Apple’s Remote Login inside of the VM, simply add a forwarded port for guest:5900 to the host. You can then VNC from the host into the VM using this port.

Answers to Frequently Asked Questions

  • anka run doesn’t support TTY mode, but you could easily use POSIX streams as with regular bash tool:
    ❯ anka run VNMANE whoami > /dev/null
    
    ❯ cat file-on-host.txt | anka run 12.0-beta md5
    ff1a596f13d348b63218078c6598ab5e
    

What’s next?