You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guides/ruby/containerize.md
+101-8Lines changed: 101 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,19 +18,112 @@ aliases:
18
18
19
19
## Overview
20
20
21
-
This section walks you through containerizing and running a Ruby on Rails application.
21
+
This section walks you through containerizing and running a [Ruby on Rails](https://rubyonrails.org/) application.
22
22
23
-
## Get the sample application
23
+
Starting from Rails 7.1 [Docker is supported out of the box](https://guides.rubyonrails.org/7_1_release_notes.html#generate-dockerfiles-for-new-rails-applications). This means that you will get a `Dockerfile`, `.dockerignore` and `bin/docker-entrypoint` files generated for you when you create a new Rails application.
24
24
25
-
The sample application uses the popular [Ruby on Rails](https://rubyonrails.org/) framework.
25
+
If you have an existing Rails application, you will need to create the Docker assets manually. Unfortunately `docker init` command does not yet support Rails. This means that if you are working with Rails, you'll need to copy Dockerfile and other related configurations manually from the examples below.
26
26
27
-
Clone the sample application to use with this guide. Open a terminal, change directory to a directory that you want to work in, and run the following command to clone the repository:
Rails 7.1 generates multistage Dockerfile out of the box, below is an example of such file generated from a Rails template.
32
30
33
-
## Initialize Docker assets
31
+
> Multistage Dockerfiles help create smaller, more efficient images by separating build and runtime dependencies, ensuring only necessary components are included in the final image. Read more about multi-stage builds [in a dedicated article](/get-started/docker-concepts/building-images/multi-stage-builds/)
32
+
33
+
34
+
```dockerfile {collapse=true,title=Dockerfile}
35
+
# syntax=docker/dockerfile:1
36
+
# check=error=true
37
+
38
+
# This Dockerfile is designed for production, not development.
39
+
# docker build -t app .
40
+
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name app app
41
+
42
+
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
43
+
44
+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
45
+
ARG RUBY_VERSION=3.3.6
46
+
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
47
+
48
+
# Rails app lives here
49
+
WORKDIR /rails
50
+
51
+
# Install base packages
52
+
# Replace sqlite3 with libpq-dev if using PostgreSQL, or libmysqlclient-dev if using MySQL
0 commit comments