> docker image pull ruby:2.6
2.6: Pulling from library/ruby
90fe46dd8199: Downloading [=======================> ] 24.09MB/50.38MB
35a4f1977689: Download complete
bbc37f14aded: Download complete
74e27dc593d4: Downloading [===========> ] 12.11MB/51.83MB
4352dcff7819: Downloading [==========> ] 38.61MB/192.2MB
cffd0bce6043: Waiting
342084bc3791: Waiting
00830f8007ce: Waiting
...
...
Digest: sha256:a16808c92f50c6be34be65da57f22b58bc5e7fbea4707b9cfe2516898b0f3922
Status: Downloaded newer image for ruby:2.6
docker.io/library/ruby:2.6
>_
> docker container run -ti --rm ruby:2.6 bash
root@41a8326ef001:/>
root@41a8326ef001:/> ps uxa
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 3864 3256 pts/0 Ss 15:53 0:00 bash
root 8 0.0 0.1 7636 2660 pts/0 R+ 15:56 0:00 ps uxa
root@41a8326ef001:/>_
root@41a8326ef001:/> gem install rails
...
root@41a8326ef001:/> rails --version
Rails 6.0.2.2
root@41a8326ef001:/>_
root@41a8326ef001:/> exit
>_
> docker run --rm -ti ruby:2.6 bash
root@41a8326ef001:/> rails
bash: rails: command not found
root@41a8326ef001:/> _
# Dockerfile
FROM ruby:2.6
RUN gem install rails
> docker build -f Dockerfile -t rails:6.0 .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM ruby:2.6
---> 5d2ee2444c80
Step 2/2 : RUN gem install rails
---> Running in be541c362bc8
Successfully installed concurrent-ruby-1.1.6
HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.
If you are upgrading your Rails application from an older version of Rails:
Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.
If you are starting a NEW Rails application, you can ignore this notice.
For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
Successfully installed i18n-1.8.2
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.7
...
...
40 gems installed
Removing intermediate container be541c362bc8
---> 8cb455dd004c
Successfully built 8cb455dd004c
Successfully tagged rails:6
> docker run --rm -ti rails:6 bash
root@44493fd551b5:/> rails --version
Rails 6.0.2.2
docker run --rm -ti \
-v $(pwd):/bind_volume \
-v bundle_cache:/usr/local/bundle \
-v node_modules_cache:/bind_volume/simple_app/node_modules \
-p "3000:3000" \
rails:6 bash
root@44493fd551b5:/>
root@44493fd551b5:/> cd /bind_volume
root@44493fd551b5:/> rails new simple_app
... (all the output of the rails new command goes here)
root@44493fd551b5:/> rails s -b 0.0.0.0
I should see it using my browser...
root@44493fd551b5:/> exit
>_
I should not be able to access the rails app from my browser.
docker run --rm -ti \
-v $(pwd):/bind_volume \
-v bundle_cache:/usr/local/bundle \
-v node_modules_cache:/bind_volume/simple_app/node_modules \
-p "3000:3000" \
-w /bind_volume
rails:6 rails s -b 0.0.0.0
Thanks to the volumes I've used, everything I needed to be persisted, was persisted
> git clone https://github.com/alfonso-slides/docker-and-rails-where-to-start-multicontainer-app.git multicontainer_app
> cd multicontainer_app
version: '3'
services:
db:
image: postgres:12
volumes:
- db_data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=development
web:
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
working_dir: '/app'
command: ["rails", "s", "-b", "0.0.0.0"]
volumes:
- .:/app
- gems_cache:/usr/local/bundle
- node_modules_cache:/app/node_modules
depends_on:
- db
volumes:
db_data:
gems_cache:
node_modules_cache:
> docker-compose run --rm web bundle install
> docker-compose run --rm web rails yarn:install
> docker-compose run --rm web rails db:create
> docker-compose run --rm web rails db:schema:load
> docker-compose run --rm web rails db:seed
> docker-compose up