I learned about Docker and decided to introduce Docker to existing Rails apps, so I did it while referring to the official quick start. I am posting the error that occurred at that time as a memorandum.
Ruby '2.6.5' Rails '6.0.0' Docker for Mac installed
FROM ruby:2.6.5 RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs yarn RUN mkdir /(app name) WORKDIR /(app name) COPY Gemfile /(app name)/Gemfile COPY Gemfile.lock /(app name)/Gemfile.lock RUN bundle install COPY . /(app name) 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"]
The following error occurs when trying to launch with% docker-compose build
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /assist/Gemfile.lock. (Gem::GemNotFoundException) To update to the latest version installed on your system, run `bundle update --bundler`. To install the missing version, run `gem install bundler:2.1.4` from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path' from /usr/local/bin/bundle:23:in `<main>' ERROR: Service 'web' failed to build : The command '/bin/sh -c bundle install' returned a non-zero code: 1
Inserting RUN gem install bundler solves it!
(Omitted) COPY Gemfile.lock /(app name)/Gemfile.lock RUN gem install bundler RUN bundle install (Omitted)
After investigating, it seems that the cause is that the version of bundler in the local environment and Docker is different, so an error occurred. If you put gem install bundler, it will be solved for the time being. .. .. There are still more. .. ..
version: "3" services: db: image: mysql:5.6.47 environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: root ports: - "3000:3000" volumes: - ./db/mysql/volumes:/var/lib/mysql web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" stdin_open: true tty: true volumes: - .:/(app name) - gem_data:/usr/local/bundle ports: - "3000:3000" depends_on: - db volumes: mysql_data: gem_data:
After the docker-compose build was successful, when I ran the docker-compose up -d command,
ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint myapp_web_1 (ae889e882d7c9f8b72f9c9b244159d86662f4abebef7d15fac4016573fe56de4): Bind for 0.0.0.0:3000 failed: port is already allocated ERROR: Encountered errors while bringing up the project.
Since the port numbers of the DB server and the web server were the same for 3000, I think the cause is that the web server does not start. It was a simple mistake. ..
I changed the DB port number to 3306 and fixed it.
(Omitted) ports: - "3306:3306"
After resolving the previous error, when I try to execute the docker-compose up command again, the following error occurs.
warning Integrity check: System parameters don't match error Integrity check failed error Found 1 errors. web_1 | web_1 | web_1 | ======================================== web_1 | Your Yarn packages are out of date! web_1 | Please run `yarn install --check-files` to update. web_1 | ======================================== web_1 | web_1 | web_1 | To disable this check, please change `check_yarn_integrity` web_1 | to `false` in your webpacker config file (config/webpacker.yml). web_1 | web_1 | web_1 | yarn check v1.22.5 web_1 | info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command. web_1 | web_1 | web_1 | Exiting
At first glance, I felt as if I should upgrade yarn, so I ran the yarn upgrade command, but it didn't change. .. ..
If you take a closer look at the error statement, ...
web_1 | To disable this check, please change `check_yarn_integrity` web_1 | to `false` in your webpacker config file (config/webpacker.yml).
Because there was a description like, when I went to the corresponding directory immediately
(Omitted) check_yarn_integrity: false
was! !! It was true by default, so rewriting it to false solved it! !! !! I will go to the last one. .. ..
docker-compose up -d succeeds and tries to access on localhost: 3000
It was simple. I forgot the db: create command. .. ..
% docker-compose exec web rails db:create % docker-compose exec web rails db:migrate
Since the view file was completely corrupted, I will investigate the cause. .. .. ..