Skip to content

Commit 7b6fa56

Browse files
Removed old Docker assets examples from the Ruby guide
1 parent 0fa6708 commit 7b6fa56

File tree

1 file changed

+21
-304
lines changed

1 file changed

+21
-304
lines changed

content/guides/ruby/containerize.md

Lines changed: 21 additions & 304 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,34 @@ EXPOSE 80
127127
CMD ["./bin/thrust", "./bin/rails", "server"]
128128
```
129129

130-
The Dockerfile above assumes you are using Thruster and Puma as the application server. In case you are using any other server, you can replace the last three lines with the following:
130+
The Dockerfile above assumes you are using Thruster together with Puma as an application server. In case you are using any other server, you can replace the last three lines with the following:
131131

132132
```dockerfile
133133
# Start the application server
134134
EXPOSE 3000
135135
CMD ["./bin/rails", "server"]
136136
```
137137

138-
Besides the Dockerfile you will also need a `.dockerignore` file. This file is used to exclude files and directories from the context of the build. Below is an example of a `.dockerignore` file.
138+
We specified the Docker entrypoint as `./bin/docker-entrypoint` which is a script that prepares the database and runs the application server. Below is an example of such a script.
139+
140+
```bash {title=docker-entrypoint}
141+
#!/bin/bash -e
142+
143+
# Enable jemalloc for reduced memory usage and latency.
144+
if [ -z "${LD_PRELOAD+x}" ]; then
145+
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
146+
export LD_PRELOAD
147+
fi
148+
149+
# If running the rails server then create or migrate existing database
150+
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
151+
./bin/rails db:prepare
152+
fi
153+
154+
exec "${@}"
155+
```
156+
157+
Besides the two files above you will also need a `.dockerignore` file. This file is used to exclude files and directories from the context of the build. Below is an example of a `.dockerignore` file.
139158

140159
```text {collapse=true,title=".dockerignore"}
141160
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
@@ -199,308 +218,6 @@ services:
199218
- "3000:80"
200219
```
201220
202-
203-
Now that you have an application, you can create the necessary Docker assets to
204-
containerize your application. You can use Docker Desktop's built-in Docker Init
205-
feature to help streamline the process, or you can manually create the assets.
206-
207-
`docker init`, the command for bootstrapping the Docker-related assets for a project, does not yet support the Ruby programming language. This means that if you are working with Ruby, you'll need to create Dockerfiles and other related configurations manually.
208-
209-
Inside the `docker-ruby-on-rails` directory, create the following files:
210-
211-
Create a file named `Dockerfile` with the following contents.
212-
213-
```dockerfile {collapse=true,title=Dockerfile}
214-
# syntax=docker/dockerfile:1
215-
216-
# Use the official Ruby image with version 3.2.0
217-
FROM ruby:3.2.0
218-
219-
# Install dependencies
220-
RUN apt-get update -qq && apt-get install -y \
221-
nodejs \
222-
postgresql-client \
223-
libssl-dev \
224-
libreadline-dev \
225-
zlib1g-dev \
226-
build-essential \
227-
curl
228-
229-
# Install rbenv
230-
RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv && \
231-
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc && \
232-
echo 'eval "$(rbenv init -)"' >> ~/.bashrc && \
233-
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build && \
234-
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
235-
236-
# Install the specified Ruby version using rbenv
237-
ENV PATH="/root/.rbenv/bin:/root/.rbenv/shims:$PATH"
238-
RUN rbenv install 3.2.0 && rbenv global 3.2.0
239-
240-
# Set the working directory
241-
WORKDIR /myapp
242-
243-
# Copy the Gemfile and Gemfile.lock
244-
COPY Gemfile /myapp/Gemfile
245-
COPY Gemfile.lock /myapp/Gemfile.lock
246-
247-
# Install Gems dependencies
248-
RUN gem install bundler && bundle install
249-
250-
# Copy the application code
251-
COPY . /myapp
252-
253-
# Precompile assets (optional, if using Rails with assets)
254-
RUN bundle exec rake assets:precompile
255-
256-
# Expose the port the app runs on
257-
EXPOSE 3000
258-
259-
# Command to run the server
260-
CMD ["rails", "server", "-b", "0.0.0.0"]
261-
```
262-
263-
Create a file named `compose.yaml` with the following contents.
264-
265-
```yaml {collapse=true,title=compose.yaml}
266-
services:
267-
web:
268-
build: .
269-
command: bundle exec rails s -b '0.0.0.0'
270-
volumes:
271-
- .:/myapp
272-
ports:
273-
- "3000:3000"
274-
```
275-
276-
Create a file named `.dockerignore` with the following contents.
277-
278-
```text {collapse=true,title=".dockerignore"}
279-
git
280-
.gitignore
281-
282-
# Created by https://www.gitignore.io/api/git,ruby,rails,jetbrains+all
283-
# Edit at https://www.gitignore.io/?templates=git,ruby,rails,jetbrains+all
284-
285-
### Git ###
286-
# Created by git for backups. To disable backups in Git:
287-
# $ git config --global mergetool.keepBackup false
288-
*.orig
289-
290-
# Created by git when using merge tools for conflicts
291-
*.BACKUP.*
292-
*.BASE.*
293-
*.LOCAL.*
294-
*.REMOTE.*
295-
*_BACKUP_*.txt
296-
*_BASE_*.txt
297-
*_LOCAL_*.txt
298-
*_REMOTE_*.txt
299-
300-
### JetBrains+all ###
301-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
302-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
303-
304-
# User-specific stuff
305-
.idea/**/workspace.xml
306-
.idea/**/tasks.xml
307-
.idea/**/usage.statistics.xml
308-
.idea/**/dictionaries
309-
.idea/**/shelf
310-
311-
# Generated files
312-
.idea/**/contentModel.xml
313-
314-
# Sensitive or high-churn files
315-
.idea/**/dataSources/
316-
.idea/**/dataSources.ids
317-
.idea/**/dataSources.local.xml
318-
.idea/**/sqlDataSources.xml
319-
.idea/**/dynamic.xml
320-
.idea/**/uiDesigner.xml
321-
.idea/**/dbnavigator.xml
322-
323-
# Gradle
324-
.idea/**/gradle.xml
325-
.idea/**/libraries
326-
327-
# Gradle and Maven with auto-import
328-
# When using Gradle or Maven with auto-import, you should exclude module files,
329-
# since they will be recreated, and may cause churn. Uncomment if using
330-
# auto-import.
331-
# .idea/modules.xml
332-
# .idea/*.iml
333-
# .idea/modules
334-
# *.iml
335-
# *.ipr
336-
337-
# CMake
338-
cmake-build-*/
339-
340-
# Mongo Explorer plugin
341-
.idea/**/mongoSettings.xml
342-
343-
# File-based project format
344-
*.iws
345-
346-
# IntelliJ
347-
out/
348-
349-
# mpeltonen/sbt-idea plugin
350-
.idea_modules/
351-
352-
# JIRA plugin
353-
atlassian-ide-plugin.xml
354-
355-
# Cursive Clojure plugin
356-
.idea/replstate.xml
357-
358-
# Crashlytics plugin (for Android Studio and IntelliJ)
359-
com_crashlytics_export_strings.xml
360-
crashlytics.properties
361-
crashlytics-build.properties
362-
fabric.properties
363-
364-
# Editor-based Rest Client
365-
.idea/httpRequests
366-
367-
# Android studio 3.1+ serialized cache file
368-
.idea/caches/build_file_checksums.ser
369-
370-
### JetBrains+all Patch ###
371-
# Ignores the whole .idea folder and all .iml files
372-
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
373-
374-
.idea/
375-
376-
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
377-
378-
*.iml
379-
modules.xml
380-
.idea/misc.xml
381-
*.ipr
382-
383-
# Sonarlint plugin
384-
.idea/sonarlint
385-
386-
### Rails ###
387-
*.rbc
388-
capybara-*.html
389-
.rspec
390-
/db/*.sqlite3
391-
/db/*.sqlite3-journal
392-
/public/system
393-
/coverage/
394-
/spec/tmp
395-
rerun.txt
396-
pickle-email-*.html
397-
398-
# Ignore all logfiles and tempfiles.
399-
/log/*
400-
/tmp/*
401-
!/log/.keep
402-
!/tmp/.keep
403-
404-
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
405-
config/initializers/secret_token.rb
406-
config/master.key
407-
408-
# Only include if you have production secrets in this file, which is no longer a Rails default
409-
# config/secrets.yml
410-
411-
# dotenv
412-
# TODO Comment out this rule if environment variables can be committed
413-
.env
414-
415-
## Environment normalization:
416-
/.bundle
417-
/vendor/bundle
418-
419-
# these should all be checked in to normalize the environment:
420-
# Gemfile.lock, .ruby-version, .ruby-gemset
421-
422-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
423-
.rvmrc
424-
425-
# if using bower-rails ignore default bower_components path bower.json files
426-
/vendor/assets/bower_components
427-
*.bowerrc
428-
bower.json
429-
430-
# Ignore pow environment settings
431-
.powenv
432-
433-
# Ignore Byebug command history file.
434-
.byebug_history
435-
436-
# Ignore node_modules
437-
node_modules/
438-
439-
# Ignore precompiled javascript packs
440-
/public/packs
441-
/public/packs-test
442-
/public/assets
443-
444-
# Ignore yarn files
445-
/yarn-error.log
446-
yarn-debug.log*
447-
.yarn-integrity
448-
449-
# Ignore uploaded files in development
450-
/storage/*
451-
!/storage/.keep
452-
453-
### Ruby ###
454-
*.gem
455-
/.config
456-
/InstalledFiles
457-
/pkg/
458-
/spec/reports/
459-
/spec/examples.txt
460-
/test/tmp/
461-
/test/version_tmp/
462-
/tmp/
463-
464-
# Used by dotenv library to load environment variables.
465-
# .env
466-
467-
# Ignore Byebug command history file.
468-
469-
## Specific to RubyMotion:
470-
.dat*
471-
.repl_history
472-
build/
473-
*.bridgesupport
474-
build-iPhoneOS/
475-
build-iPhoneSimulator/
476-
477-
## Specific to RubyMotion (use of CocoaPods):
478-
#
479-
# We recommend against adding the Pods directory to your .gitignore. However
480-
# you should judge for yourself, the pros and cons are mentioned at:
481-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
482-
# vendor/Pods/
483-
484-
## Documentation cache and generated files:
485-
/.yardoc/
486-
/_yardoc/
487-
/doc/
488-
/rdoc/
489-
490-
/.bundle/
491-
/lib/bundler/man/
492-
493-
# for a library or gem, you might want to ignore these files since the code is
494-
# intended to run in multiple environments; otherwise, check them in:
495-
# Gemfile.lock
496-
# .ruby-version
497-
# .ruby-gemset
498-
499-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
500-
501-
# End of https://www.gitignore.io/api/git,ruby,rails,jetbrains+all
502-
```
503-
504221
You should now have the following three files in your `docker-ruby-on-rails`
505222
directory.
506223

0 commit comments

Comments
 (0)