├── skeleton ├── .ruby-version ├── Gemfile ├── docker-compose.yml └── Dockerfile ├── boot2docker ├── down.sh ├── up.sh └── Vagrantfile └── README.md /skeleton/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.2.0 2 | -------------------------------------------------------------------------------- /skeleton/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '4.2.0' 3 | -------------------------------------------------------------------------------- /boot2docker/down.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | pushd `dirname $0` > /dev/null 3 | 4 | vagrant suspend 5 | 6 | popd 7 | -------------------------------------------------------------------------------- /boot2docker/up.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | pushd `dirname $0` > /dev/null 3 | 4 | vagrant up --provider parallels && \ 5 | export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2375" && \ 6 | docker version 7 | 8 | popd 9 | -------------------------------------------------------------------------------- /skeleton/docker-compose.yml: -------------------------------------------------------------------------------- 1 | db: 2 | image: postgres:9.3 3 | volumes: 4 | - ./:/var/lib/postgresql/data/ 5 | ports: 6 | - 5432 7 | web: 8 | build: . 9 | command: bundle exec rails s 10 | volumes: 11 | - .:/usr/src/app 12 | ports: 13 | - 3000:3000 14 | links: 15 | - db 16 | -------------------------------------------------------------------------------- /boot2docker/Vagrantfile: -------------------------------------------------------------------------------- 1 | VAGRANTFILE_API_VERSION = "2" 2 | 3 | Vagrant.require_version ">= 1.6.3" 4 | 5 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 6 | config.vm.define "boot2docker" 7 | 8 | config.vm.box = "parallels/boot2docker" 9 | 10 | config.vm.network "private_network", ip: "192.168.33.10" 11 | 12 | config.vm.synced_folder "/Users", "/Users", type: "nfs" 13 | 14 | # Fix busybox/udhcpc issue 15 | config.vm.provision :shell do |s| 16 | s.inline = <<-EOT 17 | if ! grep -qs ^nameserver /etc/resolv.conf; then 18 | sudo /sbin/udhcpc 19 | fi 20 | cat /etc/resolv.conf 21 | EOT 22 | end 23 | 24 | # Adjust datetime after suspend and resume 25 | config.vm.provision :shell do |s| 26 | s.inline = <<-EOT 27 | sudo /usr/local/bin/ntpclient -s -h pool.ntp.org 28 | date 29 | EOT 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /skeleton/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage 2 | MAINTAINER David Verhasselt 3 | 4 | # Fix apt-get error messages 5 | ENV DEBIAN_FRONTEND noninteractive 6 | 7 | RUN apt-get update 8 | 9 | # Install git 10 | RUN apt-get install -y git 11 | 12 | # Install ruby build environment 13 | RUN apt-get install -y build-essential autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev libssl-dev 14 | 15 | # For nokogiri 16 | RUN apt-get install -y libxml2-dev libxslt1-dev 17 | 18 | # For mysql 19 | RUN apt-get install -y libmysqlclient-dev 20 | 21 | # For postgres 22 | RUN apt-get install -y libpq-dev 23 | 24 | # For nokogiri 25 | RUN apt-get install -y libxml2-dev libxslt1-dev 26 | 27 | # For capybara-webkit 28 | RUN apt-get install -y libqt4-webkit libqt4-dev xvfb 29 | 30 | # For a JS runtime 31 | RUN apt-get install -y nodejs 32 | 33 | # Get ruby-build 34 | RUN mkdir /sources 35 | RUN git clone https://github.com/sstephenson/ruby-build.git /sources/ruby-build 36 | RUN /sources/ruby-build/install.sh 37 | 38 | # Set up app directory 39 | RUN mkdir /app 40 | WORKDIR /app 41 | 42 | # Install ruby 43 | ENV CONFIGURE_OPTS --disable-install-doc 44 | ADD .ruby-version ./ 45 | RUN ruby-build $(cat .ruby-version) /sources/ruby/ 46 | ENV PATH /sources/ruby/bin:$PATH 47 | 48 | # Install gems 49 | RUN echo 'gem: --no-rdoc --no-ri' >> /.gemrc 50 | RUN gem install bundler 51 | ADD Gemfile* /app/ 52 | RUN bundle install 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockup 2 | 3 | This is a collection of the scripts I'm using to set up my ideal docker environment. 4 | 5 | There are two parts: 6 | 7 | ## `boot2docker` 8 | 9 | Contains the scripts I use to start and stop `boot2docker` on Parallels using Vagrant to control the VM, and load in the required `DOCKER_HOST` environment variable. 10 | 11 | ## `skeleton` 12 | 13 | Contains some nice default `Dockerfile` and `docker-compose.yml` to use when setting up a new Rails dev environment. 14 | 15 | # Usage 16 | 17 | ## `boot2docker` 18 | 19 | Source the script `up.sh` to load the vagrant image, and load the `DOCKER_HOST` variable. I attach it to an alias like so: 20 | 21 | ``` 22 | alias dockup="source ~/scripts/dockup/up.sh" 23 | alias dockdown="~/scripts/dockup/down.sh" 24 | ``` 25 | 26 | You'll note that this will always use the same Vagrant box, no matter where you execute it. Since the Vagrant box is merely a host for the `docker` containers, I didn't want to create a new box for every app I'm running docker with, which saves on space. 27 | 28 | Here's the output with the above `alias`es set: 29 | 30 | ``` 31 | $ dockup 32 | Bringing machine 'default' up with 'parallels' provider... 33 | ==> default: Checking if box 'parallels/boot2docker' is up to date... 34 | ==> default: Forwarding ports... 35 | default: 2375 => 2375 36 | ==> default: Resuming suspended VM... 37 | ==> default: Waiting for machine to boot. This may take a few minutes... 38 | default: SSH address: 10.211.55.6:22 39 | default: SSH username: docker 40 | default: SSH auth method: private key 41 | ==> boot2docker: Exporting NFS shared folders... 42 | ==> boot2docker: Preparing to edit /etc/exports. Administrator privileges will be required... 43 | Password: 44 | ==> boot2docker: Mounting NFS shared folders... 45 | ==> default: Machine booted and ready! 46 | Client version: 1.5.0 47 | Client API version: 1.17 48 | Go version (client): go1.4.1 49 | Git commit (client): a8a31ef 50 | OS/Arch (client): darwin/amd64 51 | Server version: 1.5.0 52 | Server API version: 1.17 53 | Go version (server): go1.4.1 54 | Git commit (server): a8a31ef 55 | ``` 56 | 57 | As you can see, it's possible Vagrant will ask for your OS X password. This is so the VM can mount the local paths using NFS. 58 | 59 | ``` 60 | $ dockdown 61 | ==> default: Clearing any previously set forwarded ports... 62 | ==> default: Saving VM state and suspending execution... 63 | ``` 64 | 65 | Every time you want to use `docker`, make sure you run `dockup` once in your shell, which will set up the correct `DOCKER_HOST` variable: 66 | 67 | ``` 68 | $ dockup 69 | # ... 70 | $ docker ps 71 | # ... 72 | ``` 73 | 74 | ## History 75 | 76 | Steps to get here 77 | 78 | - Install vagrant 79 | - Install boot2docker (optional?) 80 | - Install docker (homebrew) 81 | - Install vagrant-boot2docker https://github.com/Parallels/boot2docker-vagrant-box 82 | 83 | ``` 84 | $ vagrant plugin install vagrant-parallels 85 | $ vagrant init parallels/boot2docker # In the path where dockup.sh lives 86 | ``` 87 | 88 | ## skeleton 89 | 90 | This is my standard go-to Rails development skeleton. It install the correct ruby version using the `.ruby-version` file (required). 91 | 92 | The web docker image starts from the `phusion/baseimage` which is optimized for running daemons as well as a command. This to solve the problem where the web instance might require multiple daemons to run on the same container. An example is runnign Thinking Sphinx which requires a Rails instance running on the same host as Sphinx. 93 | 94 | 95 | ``` 96 | docker build . 97 | docker-compose run 98 | ``` 99 | 100 | Every time Gemfile is changed, run docker build again which will install the correct gems. 101 | 102 | 103 | # Sources 104 | 105 | - [ruby-build wiki](https://github.com/sstephenson/ruby-build/wiki) 106 | - [docker-compose rails](https://docs.docker.com/compose/rails/) 107 | - [Rails development with Fig](http://www.whitesmith.co/blog/a-rails-development-environment-using-docker-through-fig/#choosingrubyversion) 108 | - [Rails on docker (thoughtbot)](https://robots.thoughtbot.com/rails-on-docker) 109 | - [boot2docker using parallels](http://standalonex.com/boot2docker-using-osx-parallel/) 110 | - [boot2docker vagrant parallels box](https://github.com/Parallels/boot2docker-vagrant-box) 111 | - [docker on osx the missing guide](http://viget.com/extend/how-to-use-docker-on-os-x-the-missing-guide) --------------------------------------------------------------------------------