0
0
Ruby on Railsframework~20 mins

Docker deployment in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Deployment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run this Dockerfile for a Rails app?

Consider this Dockerfile snippet for a Rails app:

FROM ruby:3.1
WORKDIR /app
COPY Gemfile* ./
RUN bundle install
COPY . .
CMD ["rails", "server", "-b", "0.0.0.0"]

What will be the result when you build and run this container?

Ruby on Rails
FROM ruby:3.1
WORKDIR /app
COPY Gemfile* ./
RUN bundle install
COPY . .
CMD ["rails", "server", "-b", "0.0.0.0"]
AThe container builds but never runs because CMD is missing an entrypoint.
BThe container runs but the Rails server binds only to localhost, so it's inaccessible outside.
CThe container starts a Rails server accessible on all network interfaces inside the container.
DThe container fails because Gemfile is not copied before bundle install.
Attempts:
2 left
💡 Hint

Think about what the CMD command does and the effect of the -b 0.0.0.0 option.

📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this Docker Compose service for Rails

Look at this Docker Compose service snippet:

version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    command: rails server -b 0.0.0.0
    environment:
      - DATABASE_URL=postgres://user:pass@db:5432/mydb

What is the syntax error here?

Ruby on Rails
version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    command: rails server -b 0.0.0.0
    environment:
      - DATABASE_URL=postgres://user:pass@db:5432/mydb
AThe environment variable DATABASE_URL must be under quotes.
BThe volumes syntax is invalid; it should use double slashes.
CThe ports mapping should be integers, not strings.
DThe command should be an array: command: ["rails", "server", "-b", "0.0.0.0"]
Attempts:
2 left
💡 Hint

YAML allows strings but Docker Compose recommends arrays for commands with arguments.

🔧 Debug
advanced
2:00remaining
Why does the Rails app fail to connect to the database in this Docker setup?

You have a Docker Compose file with services 'web' and 'db'. The Rails app fails to connect to the database with a connection refused error.

services:
  web:
    build: .
    depends_on:
      - db
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/mydb
  db:
    image: postgres:14
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb

What is the most likely cause?

Ruby on Rails
services:
  web:
    build: .
    depends_on:
      - db
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/mydb
  db:
    image: postgres:14
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
AThe web service tries to connect before the db service is ready to accept connections.
BThe DATABASE_URL is missing the protocol prefix.
CThe db service lacks a volume for data persistence causing immediate failure.
DThe depends_on key is invalid and ignored by Docker Compose.
Attempts:
2 left
💡 Hint

depends_on only waits for container start, not readiness.

state_output
advanced
2:00remaining
What is the effect of this Dockerfile layer caching strategy on Rails app build time?

Given this Dockerfile snippet:

FROM ruby:3.1
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
RUN rails assets:precompile
CMD ["rails", "server", "-b", "0.0.0.0"]

How does this order affect build time when only app code changes?

Ruby on Rails
FROM ruby:3.1
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
RUN rails assets:precompile
CMD ["rails", "server", "-b", "0.0.0.0"]
AEvery build reruns bundle install because Gemfile is copied after app code.
BOnly the last two layers rebuild, so bundle install is cached, speeding up builds.
CAssets precompile runs before bundle install causing errors.
DThe CMD layer caches the entire build, so no rebuilds happen.
Attempts:
2 left
💡 Hint

Docker caches layers and reuses them if previous steps don't change.

🧠 Conceptual
expert
2:00remaining
Which Docker networking mode allows a Rails container to share the host's network stack?

You want your Rails Docker container to use the host machine's network directly, without port mapping. Which Docker network mode achieves this?

Ahost
Bnone
Cbridge
Doverlay
Attempts:
2 left
💡 Hint

Think about which mode removes network isolation between container and host.