Generic image for Ruby development
10K+
alpinelab/ruby-dev The main goal of this project is to have a single Docker image to develop all your Ruby projects, with all dependencies contained inside Docker (like gems, NPM packages or even Ruby itself, that won't pollute your host environment) and without anything specific to the project in the Docker image (the codebase is mounted directly from the host filesystem into the container, thus you'll never have to build the image when you add a gem or change some code).
The Docker container also provides developer-friendly tools and behaviours like persisted Ruby console history (IRB and Pry), shell history, or even auto-installing dependencies (that's right: simply change your Gemfile or package.json and bundle install or yarn install will be run automatically for you and only when necessary). It also provides a few CLI tools to get your hands dirty, but as least as possible: vim, nano, heroku.
The default command (when you just docker-compose up) is to run foreman start, thus starting whatever you put in your Procfile. All commands are run inside the container as the same user that owns your codebase (thus probably your host user), which means that any file generated inside the container (think of rails generate, yarn init, or even log files) will be owned by yourself (not by root, like they would with a default Docker configuration).
We try to use sane default conventions so you don't have to think about it, but this image also allows some configuration (e.g. Heroku CLI or Git authentication) and customisationâ (install extra software inside the container). See the recipes bookâ for more details.
TL;DR đ
- your codebase is 2-way-mounted from your host to
/appinside the container- Yarnâ is configured to store installed modules in
/app/node_modules- Bundlerâ is configured to store installed gems in
/bundle- Rubygemsâ is configured to store installed gems (using
gem install âĻdirectly) in/bundle/global- everything ran inside the container is done with your host user UID and GID
bundle installis run before any command, only if necessaryyarn installis run before any command, only if necessary- you can customiseâ the image with extra software
Simply create a docker-compose.yml file in your project root directory like this:
version: "3"
volumes:
bundle: { driver: local }
node_modules: { driver: local }
config: { driver: local }
services:
app:
image: alpinelab/ruby-dev
ports: ["5000:5000"]
volumes:
- .:/app
- bundle:/bundle
- node_modules:/app/node_modules
- config:/config
đĄ Feel free to use
alpinelab/ruby-dev:<ruby-version>: we support multiple Ruby versions as Docker tagsâ
â ī¸ Use your actual application name suffixed with
-syncinstead ofyour_app-syncto prevent conflicts between your projects.
install it with gem install docker-sync
add a docker-sync.yml file:
version: "3"
syncs:
your_app-sync:
src: ./
sync_excludes: [log, tmp, .git, .bundle, .idea, node_modules]
add the sync container as external container in docker-compose.yml:
volumes:
your_app-sync: { external: true }
use it by replacing - ./:/app with - your_app-sync:/app:nocopy in docker-compose.yml
start the sync with docker-sync start
You can now start your project with:
docker-compose up
Or run any command (like rake, bash, or whatever else) with:
docker-compose run app [rake|bash|...]
đĄ Note that you don't need to prefix commands with
bundle exec.
You can even bypass dependencies check before the command is run by overriding the entrypoint from the command-line:
docker-compose run --entrypoint=bypass app bash
You can customise this image by building your own image based on this one (or any of its tags, by appending them to the FROM step of the Dockerfile), and install additional software on top of it:
create a Dockerfile in your project root folder, and add a build step that installs the APT package you need (other installation methods work too, but it's out of the scope of this documentation):
FROM alpinelab/ruby-dev
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends --no-install-suggests \
<INSERT APT PACKAGE NAME HERE> \
&& rm -rf /var/lib/apt/lists/*
change your docker-compose.yml to use this Dockerfile (rather than an upstream image) and to build it on-demand:
* change this line:
image: alpinelab/ruby-dev
* into this line:
```yaml
build: .
```
âšī¸ To temporarily install a package inside the container (e.g. for a one-time debugging session), you can simply run the following command from a shell inside the container:
apt-get update && apt-get install <your_package>
A wild node_modules directory owned by root may appear in your codebase directory. This is due to Docker creating the destination mount pointâ for the bind mount. It should be solved when we will be able to reliably configure Yarn to use an absolute directoryâ (instead of relative node_modules) outside of the codebase, like we do with Bundler.
The following Ruby versions are not maintained anymore:
You will still find images on DockerHubâ tagged for these versions, but branches have been removed from the Git repository and new images for them are not automatically built anymore. Thus, they must be considered as obsolete đ
Contributions are indeed warmly welcome as pull requestsâ , or issuesâ â¤ī¸
There's also a handy add-ruby-version-support.shâ script to add support for a Ruby version and another handy rebase-all.shâ script to apply a change made on latest branch to all other branches.
This project is developed by Alpine Labâ and released under the terms of the MIT licenseâ .
Content type
Image
Digest
sha256:da552d4f6âĻ
Size
488.2 MB
Last updated
over 1 year ago
docker pull alpinelab/ruby-dev:2.7.0