Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sfunke/db82b77e916e1b37279072c8eff795f1 to your computer and use it in GitHub Desktop.
Save sfunke/db82b77e916e1b37279072c8eff795f1 to your computer and use it in GitHub Desktop.
macOS VirtualBox headless Ubuntu Server and Docker setup

Get started

Install virtualbox and the extension pack:

brew install --cask docker virtualbox virtualbox-extension-pack

Download the ubuntu server image and create a VBox for it, the rest of the readme assumes it is named "Ubuntu Server".

Enable SSH

In the box

sudo apt install openssh-server

On the host

VBoxManage modifyvm "Ubuntu Server" --natpf1 "ssh,tcp,,3022,,22"

This will forward the ssh port 22 to the host on 3022. Next, start the server without a window:

VBoxManage startvm "Ubuntu Server" --type headless

And connect to it:

ssh -p 3022 username@127.0.0.1

Install docker

Once your ssh session is running in the box:

https://docs.docker.com/engine/installation/linux/ubuntulinux/

Add yourself to the docker and vboxsf group:

sudo usermod -aG docker,vboxsf `whoami`;
sudo reboot
  • vboxsf is needed to access shared folders.
  • docker is needed to see the docker daemon.

Shared folders

Mounting shared folders in Ubuntu Server

You can mount host folders in the VirtualBox:

https://devtidbits.com/2010/03/11/virtualbox-shared-folders-with-ubuntu-server-guest/

The only thing that's changed is the command sudo /media/cdrom/VBoxLinuxAdditions.run (not -amd64.run).

Shares are visible under /media/sf_<name-of-share>.

docker-compose

Install by running the following (curl method did not work for me so using pip):

sudo apt install python-pip;
export LC_ALL=C; # http://stackoverflow.com/questions/36394101/pip-install-locale-error-unsupported-locale-setting
pip install docker-compose;

Some handy aliases

echo "alias d='docker'" >> .bashrc;
echo "alias dc='docker-compose'" >> .bashrc;
source .bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment