From pulling docker-image of rails to launching

Let's reuse the rails environment once created with docker

It is troublesome to create docker and docker-compose once while referring to other people's ones, and then start over when you want to create an application with the same settings. So, I will upload the image I made to docker-hub so that I can easily duplicate it. This time, I will use the image created by rails 6.0.3 and mysql8.0.2. (Reference:

First, check the container ID used on docker-compose, and create an image to push from that container ID to docker-hub. Enter this command in the terminal to retrieve the state of the container. macbook-pro rails_app % docker ps -a
Output result

51334eee76eb        rails_app_web       " bash …"   2 days ago          Up 31 minutes>3000/tcp              rails_app_web_1
40f92b2d8ed5        mysql:8.0.20        "docker-entrypoint.s…"   2 days ago          Up 31 minutes       33060/tcp,>3306/tcp   rails_app_db_1 

Two containers are used, ID = 51334eee76eb Name = rails_app_web, ID = 40f92b2d8ed5, Name = mysql: 8.0.20. By the way, mysql: 8.0.20 is equivalent to tag. To push to docker hub, the image name must include the user name, so create a new image.


 For mysql, enter tag = `8.0.20`.
 If tag is not specified, latest will be set automatically.
 And finally push the image to docker hub.
`docker push Username/ImageName:tag`
 You can push with.
 Now, pull the image from here, create a container, and go to the point where you issue Yay! You ’re on Rails !.
 First, set the working directory and move it.
`mkdir /docker-rails
 cd docker-rails`
 Pull the image.
`docker pull Username/rails_app_web`
`docker pull Username/mysql`
 Create the required files.
` touch { docker-compose.yml, Gemfile, Gemfile.lock,, .env }`
 If you do not delete the build of docker-compose.yml and change the port number, you will get an error saying `port is already taken`, so be careful.
`docker-compose run --rm web rails new . --force --no-deps --database=mysql --skip-turbolinks`
 Create rails-app in the folder and install webpacker again.
`docker-compose run --rm web bin/rails webpacker:install`
 Paste database.yml in the same way to create the database.
`docker-compose run --rm web bin/rails db:create`
 Finally, launch the container in the background and you're done.
`docker-compose up -d`

Recommended Posts

From pulling docker-image of rails to launching
From introduction to use of ActiveHash
From introduction to usage of byebug
[Rails] How to convert from erb to haml
[Rails] Assigning variables from controller to JavaScript
The process of introducing Vuetify to Rails
Strict_loading function to suppress the occurrence of N + 1 problem added from rails 6.1
Environment construction of Ruby on Rails from 0 [Cloud9] (From Ruby version change to Rails installation)
[Rails] Button to return to the top of the page
[Rails] Introduction of pry-rails ~ How to debug binding.pry
[Rails] I tried to raise the Rails version from 5.0 to 5.2
How to link Rails6 Vue (from environment construction)
Rails Tutorial Chapter 1 From Zero to Deployment [Try]
Summary of moss when updating from JMockit 1.4 to 1.30
From setup to usage of Selenium wrapper Selenide
I want to play with Firestore from Rails
How to use JQuery in js.erb of Rails6
[Rails] Introducing (from view customization to registration)
[Rails] From test preparation to model unit testing [RSpec]
From the introduction of devise to the creation of the users table
How to write Scala from the perspective of Java
[Rails, JS] How to implement asynchronous display of comments
The story of migrating from Paperclip to Active Storage
[Updated from time to time] Ruby on Rails Convenient methods
[Rails] Save information from one form to multiple tables
[Rails] How to change the column name of the table
[Eclipse] Summary of environment settings * Updated from time to time
How to download images from AWS S3 (rails, carrierwave)
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
How to prevent editTextPreference of android PreferenceFragmentCompat from breaking
[Rails] How to get the contents of strong parameters
[Ruby on Rails] From MySQL construction to database change
[Ubuntu20.04] From ROS-noetic installation to SLAM simulation of turtlebot3
[Ruby On Rails] How to search and save the data of the parent table from the child table
Changes from Java 8 to Java 11
Sum from Java_1 to 100
How to write Rails
Migrate from JUnit 4 to JUnit 5
Introducing CircleCI to Rails
Introducing Bootstrap to Rails 5
[Rails] Introduction of PAY.JP
Introducing Bootstrap to Rails !!
Introduce Vue.js to Rails
Rails Tutorial/Significance of Indexing
How to uninstall Rails
From Java to Ruby !!
Cloud9 (Rails) from Github
The story of raising Spring Boot from 1.5 series to 2.1 series part2
Java to fly data from Android to ROS of Jetson Nano
Chewing Rails Tutorial [Chapter 1 From Zero to Deployment] Second Half
From 0 to Ruby on Rails environment construction [macOS] (From Homebrew installation to Rails installation)
Chewing Rails Tutorial [Chapter 1 From Zero to Deployment] First Half
How to write a migration from Rails datetime type to date type
Get to the abbreviations from 5 examples of iterating Java lists
[Ruby on Rails] Elimination of Fat Controller-First, logic to model-
From Ruby on Rails error message display to Japanese localization
How to get the longest information from Twitter as of 12/12/2016
How to Burning a Install Disk of Windows from Ubuntu
[Rails] Function to search and list products from multi-level categories
A series of steps to create portfolio deliverables with Rails
Let's summarize how to extend the expiration date of Rails