I have multiple Ruby applications that are run in crons using IronWorker. I am new to Docker and I want to test the application locally before pushing the code to Iron. How do I do that?
1 Answers
Your code can be stored privately on Iron.io and the image on Docker can include only the programming language and libraries and be made public. I've put together a "hello world" example showing how it can be done. I am using Alpine linux and the Ruby programming language along with Iron's dev packages. I also included the "pg" gem:
hello.rb
require 'pg'
puts "hello world"
Gemfile
source 'https://rubygems.org'
gem 'pg'
Dockerfile
FROM iron/ruby-2.3:dev
RUN apk update && apk upgrade
RUN gem install pg --no-ri --no-rdoc
COPY hello.rb /
RUN apk add bash
Here are the steps to get this running:
- Create public repository on Docker
In this example, the name of the Docker username is testuser and the name of the Docker repository is testrepo.
- Build image
Run the following command in a Docker Terminal. I have added a tag "0.0.1". This should be incremented with each change to the image that is pushed to Docker.
docker build -t testuser/testrepo:0.0.1 .
- Test image
Since the Dockerfile did not include an ENTRYPOINT ["ruby", "hello.rb"] line, any terminal command can be included in a "docker run" command. To get into an image with a bash prompt, you would run:
docker run -it testuser/testrepo:0.0.1 /bin/bash
Once inside of bash, you can then see if the code can be executed:
ruby hello.rb
In this example, I received the following error:
`require': cannot load such file -- json (LoadError)
To fix that, update the Dockerfile to install json and then re-test the image. Here is the updated Dockerfile:
FROM iron/ruby-2.3:dev
RUN apk update && apk upgrade
RUN gem install pg --no-ri --no-rdoc
RUN gem install json --no-ri --no-rdoc
COPY hello.rb /
RUN apk add bash
Now that we know the code will run correctly with the image, we can update the Dockerfile and push the image to Docker and the code to Iron.
- Remove hello.rb from folder and update Dockerfile
FROM iron/ruby-2.3:dev
RUN apk update && apk upgrade
RUN gem install pg --no-ri --no-rdoc
RUN gem install json --no-ri --no-rdoc
RUN apk add bash
- Re-build image
docker build -t testuser/testrepo:0.0.1 .
- Push image to Docker
docker push testuser/testrepo:0.0.1
- Register image with Iron (need iron.json file in current working directory)
iron register testuser/testrepo:0.0.1
- Zip IronWorker code
zip -r hello.zip hello.rb
- Upload worker to Iron (need iron.json file in current working directory)
iron worker upload --zip hello.zip --name hello testuser/testrepo:0.0.1 ruby hello.rb
Done! You can now schedule an IronWorker through the HUD or through their API.

- 284
- 4
- 17
-
Updating to ruby-2.3 to account for Json dependency – Evan Appleby Aug 02 '18 at 22:09