[RUBY] Environment construction method and troubleshooter at the time of joint development (rails, docker and github)

Introduction

Our web application development environment is built on ** Docker container **. The container that runs rails named web and the container that runs MySQL called db are launched at the same time with docker-compose up.

image.png

Benefits of using docker container

--Easy and fast environment construction --Easy to share and unify the environment --Avoid dependence on the local environment --You can immediately build the same environment on the server at the time of release --Lower memory consumption than traditional virtualization technology

For the above reasons, I use Docker.

environment

Ruby2.5.3 Rails5.2.2 MySQL5.7

Environment construction method

  1. Create an account on docker hub and download docker for desktop
  2. git clone to your local PC.
  3. Go to the directory and docker-compose up
  4. docker-compose exec web rails db:create
  5. docker-compose exec web rails db:migrate

--From the second time, only docker-compose up

In case of trouble (git edition)

I don't understand git at all

--Reference page: Introduction to monkey teacher's git

I want to push to github

$ git checkout -b Branch name to create

Or
$git branch The name of the branch to create
$git branch Created branch name
But yes

Make a branch with. The branch name that you can see what you are doing is good

$ git init 
$ git add (file name)Or git add.
$ git commit -m "comment"
$git push origin branch name

After pushing, a yellow bar will appear on github. If you want to reflect it in master, press Compare & pull request

I don't know the remote branch

Remote branch list display

$ git branch -r

I want to pull a branch pushed by another person locally

$ git fetch

Update your local branch to the latest

$ git pull origin REMOT_BRANCH_NAME:LOCAL_BRANCH_NAME

In case of trouble (docker edition)

When port 3000 does not start even after docker-compose up.

--The server did not shut down properly the last time you shut down docker --Reference article: https://qiita.com/JUNO-LEARN/items/d7b49f130b62f0740a1c --Try deleting tmp / pids / server.pid

I want to go inside the container

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
b9abd4473fd9        watch_project_web   "rails s -p 3000 -b …"   28 hours ago        Up 28 hours         0.0.0.0:3000->3000/tcp              watch_project_web_1
d55c5240d70d        mysql:5.7           "docker-entrypoint.s…"   28 hours ago        Up 28 hours         0.0.0.0:3306->3306/tcp, 33060/tcp   watch_project_db_1

Check the running container ID with

$ docker exec -it {Container name} bash

I want to see a database without entering a container

docker-compose exec db mysql -uroot -p

I want to use the rails command without entering the container

docker-compose exec web rails 〜〜

You can also enter a container called web and use commands directly like rails ~ ~.

Recommended Posts

Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
A reminder of Docker and development environment construction
Docker the development environment of Ruby on Rails project
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
[Introduction] Installation of Docker Desktop for Mac for the first time and setup of virtual environment construction of CentOS
Improve the performance of your Docker development environment
Rails Docker environment construction
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
SSL in the local environment of Docker / Rails / puma
Make the strongest Laravel development environment (Docker) Japan time
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
Rails6 development environment construction [Mac]
[Docker] Rails 5.2 environment construction with docker
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
Easy environment construction of MySQL and Redis with Docker and Alfred
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
Implementation method of linking multiple images to one post and posting at the same time
Rails + MySQL environment construction with Docker
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
[Rails] Get access_token at the time of Twitter authentication with Sorcery and save it in DB
Rails on Docker environment construction procedure
[Rails] About Uglifier :: Error: Unexpected token: at the time of deployment
I tried to take a look at the flow of Android development environment construction with Android Studio
[Environment construction with Docker] Rails 6 & MySQL 8
Install Rails in the development environment and create a new application
[Rails & Docker & MySQL environment construction] Could not find gem ‘mysql2 (> = 0.4.4, <0.6.0)’ in any of the gem sources listed in your Gemfile.
[Rails & Docker & MySQL environment construction] I started the container, but I can't find MySQL ...?
Launching the production environment with docker + rails (ver5.2) and errors that occurred
How to solve the local environment construction of Ruby on Rails (MAC)!
[Rails] How to solve the time lag of created_at after save method
[Processing x Java] Construction of development environment
Rails environment construction with Docker (personal apocalypse)
Building Rails 6 and PostgreSQL environment with Docker
Laravel development environment construction with Docker (Mac)
Sapper × Go (echo) × Docker development environment construction
Spring Boot + Docker Java development environment construction
[Rails 6] Change redirect destination at the time of new registration / login by devise
Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API
Build a development environment for Docker + Rails6 + Postgresql
[Order method] Set the order of data in Rails
Docker + DynamoDB local + C ++ environment construction and practice
(Basic authentication) environment variables in rails and Docker
Kaggle environment construction using official Docker and vscode
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
Rails6 [API mode] + MySQL5.7 environment construction with Docker
This and that of conditional branching of rails development
Rails development environment created with VSCode and devcontainer
Ruby on Rails development environment construction on M1 Mac
Summary of Japan time setting and display method
Wordpress local environment construction & development procedure with Docker
Environment construction of keras and tensorflow, jupyter lab by docker and connection to jupyter by port forwarding
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
Docker environment construction
Summary of frequently used commands in Rails and Docker
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
Introduction to Slay the Spire Mod Development (2) Development Environment Construction