Skip to content

Boot2Docker & Ruby on Rails Windows Script.

License

Notifications You must be signed in to change notification settings

Ducz0r/boot2docker-rails-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Boot2Docker & Ruby on Rails Windows Script

The purpose of this script is to slightly easen the Ruby on Rails development process on Windows computers when using Docker.

Docker, in a way, propagates itself as a method to allow cross-platforms developers to work on a shared project that's executed in the same virtual space throughout different host operating systems.

If the host operating system is, Windows, however, by following the standard Docker way of doing things, development & running of Ruby on Rails project is excrutiatingly slow. I wrote this script to somewhat speed that process up.

The script partially replaces the commonly used docker compose scripting system used by Docker users on Linux & Mac OS platforms.

How does it work?

Problem

On Windows operating systems, Docker runs in a special VirtualBox Linux virtual machine called boot2docker. This machine has specific shared file system with the host Windows system, and this filesystem share is the problem for the poor performance whenever you want to execute your Rails application directly from the Docker image.

The way user would normally setup his development environment on Windows would be to have a Ruby on Rails project folder on a Windows host, and then execute Rails server inside the Docker container inside the same project folder. For that approach to work, user must mount his Windows project folder inside the Docker container. And that is the reason for poor performance.

To access host Windows OS file system, boot2docker uses VirtualBox's own filesystem called vboxfs. This virtual file system is great because it works across different OS platforms, but is very slow when it comes to actually using it real-time. On Mac OS systems, there exists solution around this (see Hodor), but on Windows, there is no common alternative.

Solution

This script first starts the regular Docker container (inside boot2docker virtual machine) using vboxfs file system to mount your rails project folder inside virtual machine. Then, once inside Docker container, it copies the folder onto a virtual folder existing only inside the container, and sets up file synchronization between the two folders. User then operates only on the "mirrored" folder from inside the container, which is much faster than the regular way (you can also use that command by running wmake.sh cli nosync). Both folders are synchronized each second, and the synchronization obviously works both ways.

Tradeoffs

Of course, having to copy the entire project directory structure means that starting up the Docker container (or Rails server) takes more time than it would the normal way. The performance gain after that's done, though, is staggering. On a Rails project I'm currently using this script (~93MB), it takes additional 5-10 seconds to start, but performance gain when running rails server, rake generate, rake test and many other commands, is 7-10-times faster.

Prerequisites

  • Boot2Docker installed on the host Windows OS,
  • MinGW installed & configured on the host Windows OS,
  • Configured Dockerfile inside your RoR project folder. The Linux image used for the Docker container can probably be any Linux container, but this script was configured to work with Debian packages. The Dockerfile should also include some specifics that are neccesary for the wmake.sh to work.
    • The following 2 packages need to be installed on the container image: sudo, unison. On Debian, you can do that with the following Dockerfile instruction: RUN apt-get install -y unison sudo.
    • The user that will be running inside the container image must be a member of the sudoers group and have no sudo password requirement set. On Debian, the following Dockerfile instruction does exactly that:
       RUN useradd -ms /bin/bash -G sudo <user>
       RUN echo "<user> ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
       USER <user>
      

Usage

Open the script file wmake.sh in your favourite text editor and setup the variables depending on your host system. Then run wmake.sh help to see all options and their explanations.

Warning

This script is NOT 100% tested and might need additional furnishing. It works nicely on my Windows 8 system for a relatively lightweight Ruby on Rails web app.

Troubleshooting

  • If you see temporary .unison files in your project folder (from Windows host), following approaches might work:
    • unmark your project folder (and subfolders) on Windows host as read-only.
  • If you are getting out of of disk space errors inside your Docker containers, it means that boot2docker virtual machine is full. Run wmake.sh cclean to remove all stopped images and free disk space.

About

Boot2Docker & Ruby on Rails Windows Script.

Topics

Resources

License

Stars

Watchers

Forks

Languages