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
- Run
vagrant
- 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
- Run
vagrant up
- 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.
- 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
- Run
vagrant ssh
. - You should see Bash command prompt:
vagrant@docker-host:~$
- To change the folder to the mounted project directory, run:
cd /spotscore
. - Now you can run all the Docker and Docker Compose commands from here. To test this out, run:
docker ps
ordocker-compose ps
. You should see all the containers running. - You may now log out from the Vagrant machine by issuing:
exit
orlogout
. All the containers keep running.
Stop the Vagrant machine
- Run
vagrant halt
(forceful way) orvagrant suspend
(saves the machine current execution state). - 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
- Run
vagrant destroy
. - Vagrant asks "default: Are you sure you want to destroy the ''default' VM? [y/N]"
- Type 'y' and press Enter.
- Expected output:
==> default: Destroying VM and associated drives...
==> default: Running cleanup tasks for 'docker' provisioner...
==> default: Running cleanup tasks for 'docker_compose' provisioner...