acntech-archive / vagrant-docker-puppet

Example of using vagrant docker provider and puppet for simple node app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vagrant-docker-puppet

Example of using Vagrant, Docker and Puppet for establishing development environment for simple Node app.

Steps below shows how to iterative establish the configurations and existing configuration is updated for each step. Link to file revisions are included below (TODO) while step descriptions are more documentation of how to reproduce the process in other examples and scenarios.

Following version has been used in this project:

  • Vagrant v1.8.4
  • VirtualBox v5.0.24
  • Docker v1.12.0-rc4 (on local laptop) and v1.11.2 with Vagrant
  • Puppet (TODO)

Im using OSX as host.

This project has been inspired by Activelamp Blog posts:

and Lessons building node app docker

Step 1 - Creating Dockerfile

  1. Install Docker on your local laptop

  2. Create Dockerfile. See https://docs.docker.com/engine/reference/builder/#dockerfile-reference for more information

  3. Build Docker image docker build -t <your username>/<image name> .

  4. Verify that new image has been created docker images

  5. Run the Docker image (create new Docker container) docker run -p 49160:8080 -d --name <container name> <your username>/<image name>. Running your image with -d runs the container in detached mode, leaving the container running in the background. The -p flag redirects a public port to a private port in the container. --name flag assigns container name for easy access later on

  6. Verify that that container has been created docker ps

  7. Verify that node app has been started docker logs <container name>.

  8. Test your node app with curl -i localhost:49160 or open localhost:49160 in your web browser. You should see something like:

    HTTP/1.1 200 OK
    X-Powered-By: Express
    Content-Type: text/html; charset=utf-8
    Content-Length: 12
    Date: Sat, 16 Jul 2016 15:46:54 GMT
    Connection: keep-alive
    
    Hello world
    
  9. SSH into running Docker container by docker exec -i -t <container name> /bin/bash and verify that files are placed in src folder ls /src. Type exit to leave bash.

  10. Stop the running Docker container by docker stop <container name> and start it with docker start <container name>

References

Step 2 - Creating Vagrantfile

  1. Install Vagrant on your local laptop

  2. Install VirtualBox on your local laptop

  3. Make sure to install Vagrant plugin vagrant-vbguest to keep VirtualBox and VirtualBox Guest Additions in sync vagrant plugin install vagrant-vbguest

  4. Create 2 Vagrantfiles (template can be created by vagrant init). One vm for Docker Host (placed in /host folder) and second container for Docker Container (placed in the root folder). Note that Vagrantfile is using Ruby syntax. See https://www.vagrantup.com/docs/vagrantfile/ for more information

  5. Create and configure guest machines according to Vagrantfiles by vagrant up. See https://www.vagrantup.com/docs/cli/ for other Vagrant CLI commands

  6. Verify that Vagrant environments are running correctly by vagrant global-status --prune. You should see output like this:

    id       name    provider   state   directory
    cb02b94  default virtualbox running /Users/ismarslomic/src/vagrant-docker-puppet/host
    8290b77  default docker     running /Users/ismarslomic/src/vagrant-docker-puppet
    

    As you can see, we have two environments: first is the Docker Host running inside VirtualBox while second is the Docker Container. Both has running state.

  7. Test your node app with curl -i localhost:49161 or open localhost:49161 in your web browser. You should still see something like:

    HTTP/1.1 200 OK
    X-Powered-By: Express
    Content-Type: text/html; charset=utf-8
    Content-Length: 12
    Date: Sat, 16 Jul 2016 15:46:54 GMT
    Connection: keep-alive
    
    Hello world
    
  8. If you do any changes to Vagrantfiles or Dockerfile after environment are running (vagrant up) you should use vagrant reload --provision. The flag --provision will make sure to re-run the Docker provision

  9. You can shut down running Vagrant machines by using vagrant halt <machine id> (machine id can be found by vagrant global-status)

  10. You can remove running Vagrant machines by using vagrant destroy -f <machine id>. Note that this command will destroy all resources created during creation process, including data inside vm/container

  11. Login into guest machine docker-host (by using VirtualBox GUI). Use vagrant as username and password. You can also SSH into the machine by running vagrant ssh <virtualbox machine id>. After you have SSH into Docker Host you can SSH into running Docker Container by docker exec -i -t <container name> /bin/bash. Type exit to leave bash.

References

About

Example of using vagrant docker provider and puppet for simple node app


Languages

Language:Ruby 82.3%Language:Shell 9.7%Language:JavaScript 8.0%