Created
July 17, 2020 13:18
-
-
Save jesuslerma/e74ccab5a95e38b1386e16fbdc57e214 to your computer and use it in GitHub Desktop.
Simple notes on how to run ruby in containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is for running an irb | |
docker run --it --rm ruby:2.5 | |
# This is for running an script | |
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp ruby:2.5 ruby hello_world.rb | |
# this is the content we should put in hello_world.rb Make sure to add the first line | |
# #!/usr/bin/env Ruby | |
# puts Hello World from Dockerfile | |
# we also need to make the script executable | |
chmod u+x hello_world.rb | |
# This is for running an script via Dockerfile | |
mkdir hello_world | |
cd hello_world/ | |
vim Dockerfile | |
# this is the content we should put in Dockerfile | |
# FROM ruby:2.5 | |
## throw errors if Gemfile has been modified since Gemfile.lock | |
# RUN bundle config --global frozen 1 | |
# WORKDIR /usr/src/app | |
# COPY Gemfile Gemfile.lock ./ | |
# RUN bundle install | |
# COPY . . | |
# CMD ["./hello_world.rb"] | |
vim hello_world.rb | |
# this is the content we should put in hello_world.rb | |
# puts "Hello World" | |
vim Gemfile | |
# this is the content we should put in Gemfile | |
# source 'https://rubygems.org' do | |
## Gems here | |
#end | |
# since Dockerfile is expecting a Gemfile.lock we should generate it | |
docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app ruby:2.5 bundle install | |
# and then we should run this command to build the image | |
docker build -t my-ruby-app . | |
# if we want to run the image | |
docker run -it --rm --name my-running-script my-ruby-app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment