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:
docker run -it ubuntu
Explanationdocker run is a command used when you want to start a new container based on an image
-it are flags used when you need a container that need to be interactive, in other words, it enables you to use the terminal inside the container
ubuntu is the name of the image
After this, we are already connected with container and the next step is install prerequisites and rails 6.
To start installations, we need to update the system.
apt install git
To verify if git was correctly installed:
The output is something like this:
git version 2.25.1
apt install curl
Running the follow command, it’s possible to know if curl is installed:
The output is something like this:
curl: try 'curl --help' or 'curl --manual' for more information
apt install nodejs
You have to set some informations to correct node installation.
Use this command to verify node version:
You will see something like this:
apt install npm
The return is a version number:
Yarn is installed with curl command, by this, it’s important that you have already installed curl on your container:
curl -o- -L https://yarnpkg.com/install.sh | bash
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.
git clone https://github.com/rbenv/rbenv.git ~/.rbenvecho 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrcecho 'eval "$(rbenv init -)"' >> ~/.bashrcexec $SHELLgit clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-buildapt-get install -y libreadline-dev zlib1g-dev libpq-devrbenv install 2.7.1rbenv global 2.7.1
And the terminal will show you ruby version.
You need to install bundler:
gem install bundler
And run the command:
Installing Rails 6
To install Rails 6, we will use gem.
gem install rails -v 6.0.0rbenv rehash
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.
docker commit container_id image_name:tagExample:
docker commit 83f5accb104a rails6:1.0
To know your container_id, you can run the following command on terminal:
docker ps -a
And you will search some id as in the picture.
Explanationdocker commit - command used to commit a change or create an image
container_id - identifier that references a container
image_name - name that you want to put on your image
tag - your image version
Thank you for read everything, and I hope this post have helped you.
And I’m open-minded to receive feedbacks about my first post.
Como instalar o Git no Ubuntu 18.04 | DigitalOcean
Os sistemas de controle de versão são cada vez mais indispensáveis no desenvolvimento de software moderno uma ver que o…
How to Install and Use Curl on Ubuntu 18.04
You are following a tutorial where a file is downloaded using the curl utility. You run the command and you get the…
Loading... No Debian e no Ubuntu você pode instalar o Yarn através do nosso repositório de pacotes Debian.
Como instalar o Node.js no Ubuntu 18.04 | DigitalOcean
How to Install Ruby 2.7 & Rails 6 on Ubuntu 20.04
In this tutorial, we'll see how we can install the latest version of Ruby v2. 7on Ubuntu 20.04 Disco Dingo. and next…
Picture taken from:
Negócio foto criado por katemangostar em br.freepik.com