[RUBY] Error encountered with notes when deploying docker on rails

dockerfile

FROM ruby:2.5.1
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN mkdir /myapp
ENV APP_ROOT /myapp
WORKDIR $APP_ROOT
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

entrypoint.sh Directly under the project directory

entrypoint.sh


#!/bin/bash
set -e

rm -f /myapp/tmp/pids/server.pid

exec "$@"

docker-compose-yml

docker-compose.yml


version: '3'
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    tty: true
    stdin_open: true
    depends_on:
      - db
    ports:
      - "3000:3000"
    volumes:
      - .:/myapp:delegated
  db:
    image: mysql:5.7
    environment:
      MYSQL_USER: root
      MYSQL_ROOT_PASSWORD: password
    ports:
      - '3316:3306'
    volumes:
      - ./db/mysql/volumes:/var/lib/mysql

docker command related

#Container list(Including those that are stopped)
$ docker ps -a

#Container ID list
$ docker ps -a -q

#Delete container
$ docker rm [Container ID]

#(Forced) container deletion
$ docker rm -f [Container ID]

#Go inside the container
$ docker-compose exec web bash

#(1) Exit the container
$ exit
 
# (2)Get out of the container
Ctrl + P + Q (Without stopping the container)

Differences between docker-compose build, up, start, run

docker-compose build Build only the image, not the container. Of course, it doesn't even start the container

docker-compose up If there is an image cache, build and start the container from there. If there is no image cache, build the image with build and build / start the container.

docker-compose start

Launch any already built containers, if any (Stop the container with docker-compose stop)

docker-compose run Execute the command in the container of the service specified by the argument

$ docker-compose run web rails s
$ docker-compose run web rails c

etc,,,,

Reference site for docker command

https://qiita.com/tegnike/items/bcdcee0320e11a928d46 [Reverse lookup of docker-compose command for beginners](https://qiita.com/okyk/items/a374ddb3f853d1688820 #) [Docker-compose command summary](https://qiita.com/wasanx25/items/d47caf37b79e855af95f#%E5%8F%82%E8%80%83%E3%83%AA%E3%83%B3%E3%82 % AF #)

If docker is slow

[Mac docker will be free from slow stress](https://qiita.com/ysKey2/items/346c429ac8dfa0aed892 #)

docker-compose.yml


#Example
services:
  app:
    volumes:
      - .:/project/sample_app:delegated

Error encountered

Autoprefixer doesn’t support Node v4.8.2.

web_1  | ActionView::Template::Error (Autoprefixer doesn’t support Node v4.8.2. Update it.):
web_1  |     3:   <head>
web_1  |     4:     <title><%= content_for?(:html_title) ? yield(:html_title) : "Japanepa.com" %></title>
web_1  |     5:     <%= csrf_meta_tags %>
web_1  |     6:     <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
web_1  |     7:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
web_1  |     8:     <%= Gon::Base.render_data %>
web_1  |     9:     <%= include_gon %>

Autoprefixer doesn’t support Node v4.8.2. "The thing that automatically adds Vender Prefixes is that the Gem called Autoprefixer doesn't support Node v4.8.2."

1. Measures for Autoprefixer do n’t support Node v4.8.2.

Ruby on Rails - Autoprefixer doesn’t support Node v4.9.1. Update it. How to fix? It seems that it can be fixed by inserting a gem called "mini_racer"

2. Measures for Autoprefixer do n’t support Node v4.8.2.

Autoprefixer doesn’t support Node v4.8.2. Update it

#Change before
RUN apt-get update -qq \ && apt-get install -y nodejs postgresql-client

#After change
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*

Your Ruby version is 2.5.8, but your Gemfile specified 2.5.1 Error caused by different version of ruby However, the gemfile and dockerfile said:

source 'https://rubygems.org'
ruby '2.5.1'
FROM ruby:2.5.1

Countermeasures for Your Ruby version is 2.5.8, but your Gemfile specified 2.5.1

When I looked it up, the only solution was to match the ruby versions in the Gemfile and Dockerfile. Therefore, take the following countermeasures

"Uninstall and reinstall docker"

In fact, this solved the problem, but I can't recommend it in a too aggressive way.

Later, while investigating various dockers, I speculate that the following may be the cause.
  1. I used to launch a container with ruby 2.5.8, so that image remained.
  2. When docker-compose, instead of pulling the 2.5.1 image described in the dockerfile newly The error occurred because the previously pulled ruby 2.5.8 image was used.

I'm not very familiar with docker, but if the ruby image is pulled, will it be used regardless of the ruby version described in the Dockerfile? ??

I didn't understand the difference between docker-compose ʻup, build and start`, so I summarized it

What is a cache? Once you build Docker, a cache is created. As you know, browsers such as Google Chrome have the same function. If you have a cache, you can process it quickly when you build it from the second time onwards.

However, there are times when it is inconvenient to have a cache, such as when updating a Dockerfile. If you don't add the --no-cache option as introduced above, Docker will use the cache to build the image, so you won't see the updated Dockerfile and you won't be able to create a new image.

After all, it seems that a version difference error occurred because the cache when launching the container with the previous ruby 2.5.8 remained.

If you have an old ruby image

Remedy 1

#Docker without using cache-compose.Pull a new image with the ruby version specified by yml

$ docker-compose build --no-cache

Remedy 2

Delete old image

#Show a list of docker images

$ docker images
> REPOSITORY          TAG                   IMAGE ID            CREATED             SIZE
> ruby                2.5.1                 3c8181e703d2        22 months ago       869MB

#Delete image by specifying IMAGE ID

$ docker rmi 3c8181e703d2

that's all

Recommended Posts

Error encountered with notes when deploying docker on rails
Notes on building Rails6 / PostgreSQL with Docker Compose
Error when deploying EC2 on CircleCI
DB error on deploying with Heroku
Notes on using FCM with Ruby on Rails
[Rails] Error resolution when generating tokens with PAYJP
Introducing Rspec with Ruby on Rails x Docker
error code 400 appears when deploying with release: perform
Error deploying rails5 + Mysql to heroku with Docker-compose
python notes on docker
Rails deploy with Docker
Error when deploying EC2
When I bcrypt with node + docker, I got an error
Ruby on Rails Tutorial Troublesome notes when running on Windows
Run Rails whenever with docker
Error when playing with java
[Docker] Rails 5.2 environment construction with docker
Error when using rails capybara
[Docker] Use whenever with Docker + Rails
When I used Slick on Rails, it competed with Turbolinks.
Measures for permissions when building MySQL with Docker on WSL2
Rails + MySQL environment construction with Docker
Error when npm install on Windows 7
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Build environment with vue.js + rails + docker
General error: 1812 occurs with docker + laravel
Build Rails environment with Docker Compose
WordPress with Docker Compose on CentOS 8
Solution notes when an error occurs when downloading docker gpg using curl
Rails on Docker environment construction procedure
I tried deploying a Docker container on Lambda with Serverless Framework
[Environment construction with Docker] Rails 6 & MySQL 8
Deploy Rails on Docker to heroku
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Notes on what to do when EC2 is set up with t2.micro
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
When building rails6 environment on Ubuntu, it gets stuck with bundle install
[Ruby on Rails] Error that Couldn't find User with ... after logging out
[Ruby on Rails] View test with RSpec
Building Rails 6 and PostgreSQL environment with Docker
SCSS doesn't work when deploying Rails6 AWS
Create Rails 6 + MySQL environment with Docker compose
[Rails] How to use rails console with docker
Deploy to heroku with Docker (Rails 6, MySQL)
Try deploying a Rails app on EC2-Part 1-
Scraping with puppeteer in Nuxt on Docker.
Error when building infrastructure with aws app
[Ruby on Rails] Controller test with RSpec
Image flew when updating Docker with WSL2
[Ruby on Rails] Model test with RSpec
rails test fails with database reference error
Build an environment with Docker on AWS
Launched Redmine with Docker on Raspberry Pi 3
Let's make an error screen with Rails
Run Ubuntu + ROS with Docker on Mac
How to build Rails 6 environment with Docker
Dealing with NameError: uninitialized constant :: Analyzable error when installing Active Storage in Rails6
[Laravel] How to deal with out of memory error when composer require [Docker]
Error when using Docker or other OS frequently with Vagrant Stderr: VBoxManage.exe: error: Failed
[Error resolution] Occurs when trying to build an environment for spring with docker