Working with Vagrant - SpotScore/spotscore GitHub Wiki

NB! All the following instructions assume you are in your project root folder and use a command-line shell to run the commands.

Listing available Vagrant commands

  1. Run vagrant
  2. Vagrant displays a list of common commands. The most used are:

status
up
ssh
halt
suspend
box update
destroy

Create a new Vagrant machine and provision it with Docker

  1. Run vagrant up
  2. Vagrant does the following:
  • (Creates if it does not exist) and starts the Virtualbox virtual machine.
  • Optionally installs the new VBox Guest Addons.
  • Forwards the ports from your host machine to the Vagrant virtual machine.
  • Mounts the current project source code folder as a shared folder to /spotscore in the Vagrant virtual machine.
  • Installs Docker.
  • Provisions the Vagrant machine with Docker Compose and runs the docker-compose up command.
  • Docker will pull the images and run the containers that are described in docker-compose.yml file.
  1. Test the results:
  • Run vagrant status. Expected result: default running (virtualbox)
  • Go to localhost:3000 with your browser.
  • Connect to the PostgreSQL database (host: localhost:5432, database: gis, user: spotscore, password: notsecret).

Troubleshooting: If the ports collide with the ones that some already running services use then please change these in the Vagrantfile (temporarily) or close the other services that are listening on those ports (Skype, databases, webservers, etc).

Connect to Vagrant machine via SSH

  1. Run vagrant ssh.
  2. You should see Bash command prompt: vagrant@docker-host:~$
  3. To change the folder to the mounted project directory, run: cd /spotscore.
  4. Now you can run all the Docker and Docker Compose commands from here. To test this out, run: docker ps or docker-compose ps. You should see all the containers running.
  5. You may now log out from the Vagrant machine by issuing: exit or logout. All the containers keep running.

Stop the Vagrant machine

  1. Run vagrant halt (forceful way) or vagrant suspend (saves the machine current execution state).
  2. To start the Vagrant machine again, run: vagrant up.
    Both options should work the same, but the suspending does not actually stop the docker processes in between.

Cleaning up and starting over

  1. Run vagrant destroy.
  2. Vagrant asks "default: Are you sure you want to destroy the ''default' VM? [y/N]"
  3. Type 'y' and press Enter.
  4. Expected output:
    ==> default: Destroying VM and associated drives...
    ==> default: Running cleanup tasks for 'docker' provisioner...
    ==> default: Running cleanup tasks for 'docker_compose' provisioner...