Docker vs Vagrant

Thanks to a question of my friend Xavier: “Is this something that might potentially interest us? CoreOS Now Available On DigitalOcean!“, I reopened this internal discussion “Vagrant or Docker, this is the question?”. Well here are my thoughts ….

CoreOS is a minimal Linux Distro in order to save RAM when you manage Clusters (or slices within a machine). They promise  to use only 144MB RAM.

When you use Docker, you need a host OS in your Server (CoreOS promises to be the lighter host OS).

So the question here is …… should we use Docker?

  • SERVER SIDE:
    • Docker/CoreOS are scalability tools: as Adrian said this is a really powerful tool to scale applications, you can deploy packaged containers (slices) within a server and among servers in a farm. CoreOS seems to help a lot at this point also, running ‘etcd‘ by default.
    • Removes Lock-in: You can move your apps among providers (DO, Rackspace, AWS, Linode,… your private farm). Once you have your container configured, you just need to have a linux host (an AWS linux AMI, Ubuntu, CoreOS ….) with Docker installed.
  • DEVELOPER SIDE: Docker instead of Vagrant to emulate the system locally (take a look at this great discussion between both creators)
    • This is only possible, for the moment, if your app servers are linux (this does not mean that your Dev workstation should be Linux)
    • Docker engine (Virtualization layer) is based on LXC, which manages chroot, network, mount… all kernel “Containerizing” capabilities directly. This efficiency is extreme if your local OS is Linux.
      • Vagrant lies over VirtualBox which creates a lot of CPU and Memo overhead.
    • Portability: Docker allows to reproduce EXACTLY the production scenario in your workstation (or other environments like staging or testing). You just need Docker/Linux installed in both, and Docker acts as an abstraction layer.
      • Vagrant offers images which haven’t the same configuration as your provider’s images (I experienced this directly: ubuntu-14.04 has not the same configuration in vagrantcloud.com‘s box, and DigitalOcean.com’s image)
    • Images weight: Vagrant boxes are much larger than Docker repos (ubuntu/trusty is ~600MB image box, against 64MB as Docker repo)

I was until this weekend with an eye on this Infrastructure Maintenance Stack:

  • Chef: Manages server installation and future configurations.
  • Vagrant: reproduces (approximately) our production server in order to check configurations.
  • Capistrano: Manages continuous deployment.

But due to read (and tests) about Docker this weekend, I am thinking to substitute Vagrant per Docker (the reasons above are really persuasive).

So, hey guys!! what do you think? Is Docker/CoreOs something that might potentially interest us?

Install PostgreSQL on Ubuntu for Rails developers

These instructions worked for Ubuntu 12-14.

Check the language in the system:

env | grep LC_

It should be “en_US.UTF-8”, if not you can configure in “System Setting > Language Support”.
Installing DDBB and libpq-dev to compile rails gem when bundling, with following command:

sudo apt-get install postgresql libpq-dev

To gain access from the server it-self, In /etc/postgresql/9.3/main/postgresql.conf, uncomment the following line:

listen_addresses = 'localhost'

To have access from rails app, modify the following line in /etc/postgresql/9.1/main/pg_hba.conf:

# "local" is for Unix domain socket connections only
local   all             all                                     md5

Restart the service:

sudo service postgresql restart

You will need to add a role:

sudo -u postgres psql
create role pg_user with createdb login password 'pg_user';

Be sure that your Gemfile includes: gem ‘pg’
Create your database.yml for dev and test:

common: &common
  adapter: postgresql
  username: pg_user
  password: pg_user
 
development:
  <

Create and fill the database:

rake db:create
rake db:migrate
rake db:seed

Some Postgre useful commands are:

  • List of databases: sudo -u postgres psql -l
  • Check server encoding: sudo -u postgres psql -c “SHOW SERVER_ENCODING”