How to create a Rails 6 image in Docker — Ubuntu 18.04

Arthur Nakao
Jun 18 · 5 min read
Image for post
Image for post
How to Create a Rails 6 Image in Docker


In this post I will show you what I did to create a Rails 6 Image based on Ubuntu container. Just for information, I am doing this tutorial in Ubuntu 18.04. If you are using other operacional system, it’s important to know the differences on docker usage.

This is a simple tutorial, but I will start from this part, because I intend to show in next post how can you integrate a Rails 6 container with Postgres container WITHOUT use docker compose (there is a lot of tutorials about this USING DOCKER COMPOSE! And it was hard to me find a way to learn how can I create containers without this tool)

I don’t know you, but I’m a person that like to know exatly what I’m doing. Using docker compose I had the sensation that I was only copying and pasting a lot of informations without know exatly what was hapenning.

Before anything, I am assuming that you have docker installed on your machine.

Starting Ubuntu Container

Enough of idle, let’s start. In the first place, let’s run a container based on a Ubuntu image. To make this, you need to run the follow command:

Image for post
Image for post

Installing Prerequisites

After this, we are already connected with container and the next step is install prerequisites and rails 6.

- Git
- Curl
- Yarn
- Nodejs
- Npm
- Ruby

To start installations, we need to update the system.


To verify if git was correctly installed:

The output is something like this:

Image for post
Image for post


Running the follow command, it’s possible to know if curl is installed:

The output is something like this:

Image for post
Image for post


You have to set some informations to correct node installation.

Image for post
Image for post
Image for post
Image for post

Use this command to verify node version:

You will see something like this:

Image for post
Image for post


To verify:

The return is a version number:

Image for post
Image for post


Yarn is installed with curl command, by this, it’s important that you have already installed curl on your container:

Trying to see yarn version:

To use this command, you will need to reopen terminal.

If it return a version number, everything is correct


Take care, there are so many commands here, and they need to be used one by one.

To verify:

And the terminal will show you ruby version.

You need to install bundler:

And run the command:

Installing Rails 6

To install Rails 6, we will use gem.

To know if Rails 6 is already installed:

If the version appear like the follow, Ruby on Rails is already installed on your container.

Now, just one more step…

Create an Image

To create an image, you will only need to run one command.

To know your container_id, you can run the following command on terminal:

Image for post
Image for post

And you will search some id as in the picture.

The Startup

Medium's largest active publication, followed by +732K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store