How to set up a Ruby on Rails development environment with Docker

Locate out how to use Docker to build a Rails development framework that will make application programming and web advancement far more effective.

Jack Wallen

Ruby on Rails (aka Rails) is a website growth framework that would make application programming and world-wide-web improvement extra effective. These frameworks provide as completely ready-produced solutions for items like constructing menus, tables, or varieties for a site. For many app and website builders, Rails is a must have.

In get to work with Rails, you need to have the proper environment. How do you set up the Rails environment? With the support of Docker, you can do so pretty swiftly. I am likely to walk you by means of the method of making this sort of an ecosystem on Ubuntu Server 18.04. Inside minutes (or seconds, based on quickly you kind), you can make your 1st Rails project.

SEE: Using the services of package: Database administrator (Tech Professional Investigation)

Let’s get to get the job done.


On the off-possibility you do not already have Docker up and jogging on your server, this is how you do so:

  1. Log into your Ubuntu server.
  2. Set up Docker with the command sudo apt-get put in -y
  3. When the installation completes, incorporate your user to the docker team with the command sudo usermod -aG docker $User.
  4. Log out and log back again in.

Deploying Rails

Our up coming action is to deploy the Rails container. In advance of we do that, build a new listing with the command:

mkdir -p ~/rails

Improve into the newly designed directory with the command:

cd ~/rails

Deploy the Rails container with the command:

docker operate --rm -v $PWD:/usr/src -w /usr/src -ti ruby:alpine sh  cd app

The earlier mentioned command does the following:

  • Deploys a momentary container, dependent on ruby:alpine impression.
  • Mounts the host directory /usr/neighborhood inside the container.
  • Executes the sh shell command.
  • Drops you into the mounted /usr/local directory.

Now we can install the Rails dependencies with the command:

apk incorporate build-base

With the dependency out of the way, you can now install Rails with the command:

gem set up -N rails

The over command does consider a little bit extended than you might consider, so give it time. After it completes, you are all set to create your initially Rails venture. Crank out a new Rails task (named application with a MySQL databases) with the command:

rails new app --databases=mysql --skip-bundle

After this completes, exit out of the container with the exit command. You should really now find by yourself in the ~/rails/app directory, all set to start off creating your Rails venture. At the instant, having said that, this directory is owned by root. To alter this, problem the command:

sudo chown -R $Consumer:$User ~/rails/app

Docker compose

If you prepare on developing your Ruby on Rails initiatives with dockerfiles, you will require to make use of the docker-compose command. For this to operate appropriately, you have to have to install docker-ce, instead of the deal. This can be completed with the adhering to actions:

  1. Incorporate the needed vital with the command curl -fsSL https://down | sudo apt-key incorporate –
  2. Incorporate the repository with the command sudo incorporate-apt-repository “deb [arch=amd64] https://down $(lsb_release -cs)  stable”
  3. Set up docker-ce with the command sudo apt install -y docker-ce

After you comprehensive the earlier mentioned techniques, start out and allow docker with the commands:

sudo systemctl commence docker
sudo systemctl permit docker

Last but not least, down load the docker-compose binary with the command:

sudo curl -L$(uname -s)-$(uname -m) -o /usr/neighborhood/bin/docker-compose

Give the newly added command executable permissions with the command:

sudo chmod +x /usr/nearby/bin/docker-compose

Now, if you program on constructing Ruby on Rails assignments with dockerfiles, you might be ready.

And that is all there is to developing a Rails improvement environment with the assist of Docker. Time to start out making. Following time we visit this subject matter, we’ll explore how to construct a Rails job making use of dockerfiles.

Also see

Fibo Quantum

Be the first to comment

Leave a Reply

Your email address will not be published.