Monday, 29 September 2014

Vagrant and Docker Workflow

I've recently been looking into using both Vagrant and Docker to develop my projects.  This is the work flow that I've settled on...

  • I'll use Vagrant to support my development work
  • I'll use Docker as the mechanism for getting my projects hosted
  • Start a project with a Vagrant set up file that will launch a Debian vm and apt-get Docker installed on it
  • The Vagrant VM is used to build the code
  • The result of of the development code is to build a Docker image of the project
  • The Docker image is what is then used to deliver the project's services

As an example I created vagrant-docker-flask on GitHub to show how this works.

  1. Clone the git repo: git clone https://github.com/davegoopot/vagrant-docker-flask.git
  2. In the cloned directory run:  vagrant up
  3. You now have the dev machine image installed that you can connect to using: vagrant ssh
  4. Inside vagrant run: cd /vagrant/flaskserver/
  5. Then build the flask server image with: sudo docker build -t="local:flask" .
  6. Start up a container from the image with:  sudo docker run -d -p 5000:5000 local:flask python demo.py
  7. The flask server will run and be accessible from the original host machine at http://localhost:5000/
  8. To work on the code, you can now edit flask/demo.py, run the docker build and the docker run command again and see your changes

No comments: