“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey
Senior Software Engineer, UK

Docker yet again

I still haven’t got to grips with Docker, I need to sort out our CI environment as it’s a bit weird and stuff is missing so….let’s give Docker a whirl. I’ve already got it installed so.

Robs-MacBook-Pro:rostering rl$ docker version
Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a66213fe
 Built:             Mon Jun 22 15:41:33 2020
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a66213fe
  Built:            Mon Jun 22 15:49:27 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Run a Ruby command without that version of Ruby installed.

Robs-MacBook-Pro:rostering rl$ docker run ruby:2.7 ruby -e "puts :hello"
Unable to find image 'ruby:2.7' locally
2.7: Pulling from library/ruby
d6ff36c9ec48: Pull complete 
c958d65b3090: Pull complete 
edaf0a6b092f: Pull complete 
80931cf68816: Pull complete 
bc1b8aca3825: Pull complete 
e64edafe3f35: Pull complete 
5f7e31a225bc: Pull complete 
a7a2582e3a28: Pull complete 
Digest: sha256:4cdd89e947cc52c78c273953e42a6e9d94ca4cd182875fd50745550580b772f4
Status: Downloaded newer image for ruby:2.7
hello

And now after

Robs-MacBook-Pro:rostering rl$ docker run ruby:2.7 ruby -e "puts :hello"
hello

Ok that’s pretty cool :)

Now if we want to mount an existing directory inside our Docker instance, and boot it with interactive mode

Robs-MacBook-Pro:rostering rl$ docker run -it -v ${PWD}:/apps/rostering  ruby:2.6.6 bash
Unable to find image 'ruby:2.6.6' locally
2.6.6: Pulling from library/ruby
d6ff36c9ec48: Already exists 
root@520c19cb27a6:/# cd apps/rostering/
root@520c19cb27a6:/apps/rostering# bundle install
Traceback (most recent call last):
	2: from /usr/local/bin/bundle:23:in `<main>'
	1: from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /apps/rostering/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.1.4`
root@520c19cb27a6:/apps/rostering# gem install bundler:2.1.4
Fetching bundler-2.1.4.gem
Successfully installed bundler-2.1.4
1 gem installed

It’s effectively a new version of Ruby with no dependencies, so we need to install bundler, etc.

root@520c19cb27a6:/apps/rostering# gem install bundler:2.1.4
Fetching bundler-2.1.4.gem
Successfully installed bundler-2.1.4
1 gem installed
root@520c19cb27a6:/apps/rostering# bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/shorelabs/js-exception-notifier.git
Fetching rake 13.0.1
Installing rake 13.0.1
Fetching concurrent-ruby 1.1.6
Installing concurrent-ruby 1.1.6
Fetching aasm 5.1.0
Installing aasm 5.1.0
Fetching i18n 1.8.5
Installing i18n 1.8.5
Fetching minitest 5.14.1
.....
GPK of the Day Mean GENE