Don’t need to install a bunch of language environments on your machine. • Simulate production-like environments locally • Test easily app’s compatibility with the newer version of language or database • Ship fast
• Dockerfile – Describes how a machine image is configured. • Dockerfile – Is made up of various instructions (FROM, RUN, COPY, and WORKDIR) Docker build [options] <PATH_TO_BUILD_DIRECTORY>
in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Use Ctrl-C to stop Started GET "/" for 172.17.0.1 at 2019-06-29 04:58:31 +0000 Cannot render console from 172.17.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by Rails::WelcomeController#index as HTML Rendering /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb Rendered /usr/local/bundle/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb (5.5ms) Completed 200 OK in 27ms (Views: 17.9ms | ActiveRecord: 0.0ms)
web Step 1/6 : FROM ruby:latest ---> f1c13927d193 Step 2/6 : RUN apt-get update -yqq ---> Using cache ---> c2c436c9dd8a … Removing intermediate container ef048eaae861 ---> ae266514c8b0 Step 6/6 : RUN bundle install ….. Removing intermediate container 7d8fe53a039a ---> baf5e19c6c94 Successfully built baf5e19c6c94 Successfully tagged myapp_web:latest WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`. Creating myapp_web_1 ... done Attaching to myapp_web_1 web_1 | Switch to inspect mode. web_1 | myapp_web_1 exited with code 0
latest baf5e19c6c94 About a minute ago 1.02GB superapp latest 74a307638448 20 minutes ago 1.02GB <none> <none> 6c2873e62181 About an hour ago 1.02GB ruby latest f1c13927d193 31 hours ago 870MB
docker-compose logs [-f] <service name> - Run a one-off command in a new throwaway container $ docker-compose run --rm <service name> <command> - Run a one-off command in an existing container $ docker-compose exec <service name> <command> - Rebuild an image $ docker-compose build <sevice name>
true stdin_open: true Then attach to the process: $ docker attach $(docker-compose ps –q web) $ docker-compose run web bundle exec rspec [path_to_rspec]