Trying to run a ruby on rails app, here is the docker-compose.yml:
version: '3'
services:
postgres:
image: postgres:11
volumes:
- ./tmp/db:/app/tmp/db
environment:
POSTGRES_HOST_AUTH_METHOD: trust
app:
build: .
command: bash -c "yarn install --check-files ; rm -f tmp/pids/server.pid ; /app/bin/webpack-dev-server --host 0.0.0.0 & bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/app
- /home/$USER/.ssh:/root/.ssh
ports:
- "3000:3000"
- "3035:3035"
depends_on:
- postgres
- solr
solr:
image: solr:8.2
And here is the Dockerfile:
FROM <OMITTED>/ruby_2.5.1:latest
MAINTAINER <OMITTED>
# Install apt-get dependencies and nodejs
RUN apt-get update && apt-get install -y \
build-essential
# Set working directory for following commands
RUN mkdir -p /app
WORKDIR /app
# Copy Gemfile and then install gems through bundler
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install
# Installing nodejs, yarn, and the java runtime environment
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y yarn postgresql-client-12
RUN yarn install --check-files
RUN apt-get install -y default-jre ffmpeg nano
RUN apt-get install -y ruby-chromedriver-helper
# Copy the main application.
COPY . ./
# Start SSH agent and add key
RUN echo 'eval "$(ssh-agent -s)" &>/dev/null' >> ~/.bashrc
RUN echo 'ssh-add $(find /root/.ssh -type f ! -name "*.*" | grep id) &>/dev/null' >> ~/.bashrc
RUN yarn install --check-files
#Searches in the /.ssh directory in the container for files that do not have an extension,
#searches them for 'id' which will be a key, and then adds to the ssh agent
RUN ln -sf /usr/local/rvm/rubies/ruby-2.5.1/bin/* /usr/local/bin
# Expose port 3000 so it can be seen outside of the container
EXPOSE 3000
EXPOSE 3035
# Run the rails server
CMD ["rails", "server"]
The project is a pretty standard ruby on rails app; it uses postgresql for the database, solr for search functionality on the website, and yarn for javascript packages. When I run docker-compose up, the project builds successfully (gets through all 25 steps in the Dockerfile), the solr and postgresql images start up fine, but when it comes to the web app itself I get this error:
app_1 | yarn install v1.22.18
app_1 | Error: EACCES: permission denied, open '/app/package.json'
app_1 | at Object.openSync (fs.js:462:3)
app_1 | at Object.readFileSync (fs.js:364:35)
app_1 | at onUnexpectedError (/usr/share/yarn/lib/cli.js:88608:106)
app_1 | at /usr/share/yarn/lib/cli.js:88727:9
app_1 | bash: line 1: /app/bin/webpack-dev-server: Permission denied
app_1 | Your RubyGems version (3.0.9) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`
app_1 | Could not locate Gemfile or .bundle/ directory
<OMITTED>-rails_app_1 exited with code 10
I've tried so far:
Setting permissions (sudo chown -R $USER:$USER . and variations)
Pruning docker (running docker system prune -a)
Changing git branches (I originally thought it was some code on my feature branch causing an issue)
Rebooting computer and updating packages
None of these have remedied the issue.
Related
In Debian GNU/Linux 11 (bullseye) based Dockerfile, I tried to use CMD to run an entry point command:
#EDIT
WORKDIR "/tmp"
USER root
COPY ./entrypoint.sh /tmp/rails/entrypoint.sh
RUN chmod +x /tmp/rails/entrypoint.sh
EXPOSE 80
CMD ["/bin/bash","-c","/tmp/rails/entrypoint.sh"]
/tmp/rails/entrypoint.sh:
#!/bin/bash
nginx -g 'daemon off;'
cd /tmp
RAILS_ENV=proudction bundle exec rails server -p 3000
service nginx start
But I still getting error
/bin/bash: 1: ./entrypoint.sh: not found
I also tried
ENTRYPOINT /tmp/rails/entrypoint.sh
CMD ["/bin/bash","-c","/tmp/rails/entrypoint.sh"]
but it always show entrypoint.sh not found, Any idea?
EDIT
full docker file:
FROM ruby:3.0.5
RUN apt update -y
RUN apt install -y nginx
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.6.1 /lambda-adapter /opt/extensions/lambda-adapter
RUN apt-get update -y
RUN apt-get --assume-yes install autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
RUN apt-get install -y rubygems #ruby-dev
RUN gem install bundler -v '2.2.32'
RUN bundle config --local build.sassc --disable-march-tune-native
# UPDATE NODE:
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs
# YARN:
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt update && apt install yarn
# Fix issue with sassc gem
RUN bundle config --local build.sassc --disable-march-tune-native
RUN apt-get install -y awscli
#END OF ORIGINAL
#RUN bundle config set without 'development test'
#RUN rm -rf /home/app/webapp/app
RUN mkdir /tmp/rails
COPY . /tmp/rails
WORKDIR "/tmp/rails"
RUN bundle install # --path=vendor
ENV RAILS_SERVE_STATIC_FILES false
ENV EXECJS_RUNTIME=Disabled
ENV WEBPACKER_PRECOMPILE=false
ENV NODE_ENV=production
RUN yarn config set ignore-engines true
#RUN bundle exec rails webpacker:compile
RUN bundle exec rails assets:precompile
ARG GIT_REVISION_ARG
ENV GIT_REVISION=$GIT_REVISION_ARG
#Rails App
RUN rm -f /etc/service/nginx/down
RUN rm -f /etc/nginx/sites-enabled/default
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
RUN chmod +x /tmp/rails/entrypoint.sh
WORKDIR "/tmp"
ADD nginx/app/config/ /etc/nginx/
ADD nginx/app/images/ /usr/share/nginx/html/images
USER root
COPY ./entrypoint.sh /tmp/rails/entrypoint.sh
RUN chmod +x /tmp/rails/entrypoint.sh
ENTRYPOINT /tmp/rails/entrypoint.sh
EXPOSE 80
CMD ["/bin/bash","-c","/tmp/rails/entrypoint.sh"]
I am working on an Apple M1 Pro and running onto several issues with Docker and chromedriver.
So I want to run RSpec tests with selenium chrome headless on my Docker container. My Dockerfile is:
# Start from the official ruby image, then update and install JS & DB
FROM --platform=linux/amd64 ruby:2.6.6
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
# Install Chromedriver
RUN apt-get update && apt-get install -y unzip && \
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/ && \
unzip ~/chromedriver_linux64.zip -d ~/ && \
rm ~/chromedriver_linux64.zip && \
chown root:root ~/chromedriver && \
chmod 755 ~/chromedriver && \
mv ~/chromedriver /usr/bin/chromedriver && \
sh -c 'wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -' && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \
apt-get update && apt-get install -y google-chrome-stable
# Create a directory for the application and use it
RUN mkdir /myapp
WORKDIR /myapp
# Gemfile and lock file need to be present, they'll be overwritten immediately
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
# Install gem dependencies
RUN gem install bundler:2.2.32
RUN bundle install
RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
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 && \
apt-get update && apt-get install -y yarn
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - && \
apt-get install nodejs
COPY . /myapp
# This script runs every time the container is created, necessary for rails
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start rails
CMD ["rails", "server", "-b", "0.0.0.0"]
My docker-compose.yml is:
version: "3"
services:
db:
image: postgres
environment:
POSTGRES_USER: yyy
POSTGRES_PASSWORD: xxx
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
environment:
POSTGRES_USER: yyy
POSTGRES_PASSWORD: xxx
POSTGRES_HOST: db
My capybara.rb:
require 'capybara/rspec'
require 'selenium-webdriver'
Capybara.register_driver :selenium_chrome_headless do |app|
Capybara::Selenium::Driver.new app,
browser: :chrome,
clear_session_storage: true,
clear_local_storage: true,
capabilities: [Selenium::WebDriver::Chrome::Options.new(
args: %w[headless disable-gpu no-sandbox window-size=1024,768],
)]
end
Capybara.javascript_driver = :selenium_chrome_headless
and Gemfile:
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara'
gem 'launchy', '~> 2.4.3'
gem 'selenium-webdriver'
#To clean database for tests
gem 'database_cleaner'
# Easy installation and use of web drivers to run system tests with browsers
# gem 'webdrivers'
end
This installs the chromedriver and google-chrome-stable in the /usr/bin directory in the container:
# which chromedriver
/usr/bin/chromedriver
# which google-chrome-stable
/usr/bin/google-chrome-stable
And their version matches (I read online that if it doesn't match it gives problems):
# google-chrome-stable --version
Google Chrome 98.0.4758.80
# chromedriver --version
ChromeDriver 98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758#{#972})
So it should be working. When I try to run the test, when the test is using js:true and I am in need of a headless chrome, this error happens:
Selenium::WebDriver::Error::UnknownError:
unknown error: Chrome failed to start: crashed.
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I have been searching around but I found nothing that can help since I have the M1 chip and the answers I found didn't work.
NOTE:
Don't know if it is helpful but when I enter the container and try to run chromedriver it goes right but when running google-chrome-stable an error occurs:
# google-chrome-stable
[57:57:0210/020137.011691:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
# google-chrome-stable --no-sandbox
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[129:129:0210/020150.185829:ERROR:nacl_fork_delegate_linux.cc(329)] Bad NaCl helper startup ack (0 bytes)
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[93:137:0210/020150.317808:ERROR:file_path_watcher_linux.cc(321)] inotify_init() failed: Function not implemented (38)
[0210/020150.398311:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
Trace/breakpoint trap
I have been going around this for a long time. Do you have any idea how to solve? Thanks!
For solving the chrome and chromedriver issue in mac m1 arm64:
You can use the following docker image seleniarm/standalone-chromium:latest for arm64 architecture to run your system test using the open source Chromium browser.
seleniarm/standalone-chromium:latest
scenario1
So the problem I am facing like after building the docker images. If I am going inside the docker container and doing GEM_PATH=$GEM_HOME gem list it is not showing all the gems installed at the time of building the image. it is showing only a few gems.
scenario2
If I am not sourcing the RVM path inside the Dockerfile. Then If I am going inside the docker container and doing GEM_PATH=$GEM_HOME gem list then it is showing all the gems.
Can anyone please explain to me why this is happening and how I should install and source RVM? So I can see all the gems inside the container. Basically, I want the scenario1 should work. Thanks
Below is my Dockerfile
FROM ruby:2.6.5
RUN apt-get update -qq && apt-get install -y sudo && apt-get install -y build-essential && apt-get install -y apt-utils && apt-get install -y git
RUN gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \curl -sSL https://get.rvm.io | sudo bash -s stable --ruby && echo 'source /usr/local/rvm/scripts/rvm' >> /etc/bash.bashrc
RUN /bin/bash -l -c 'gem install bundler -v 1.17.3'
RUN /bin/bash -l -c 'gem install rails --version=5.2.4.1'
WORKDIR /app
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle config set path 'vendor/bundle'
COPY Gemfile Gemfile.lock ./
ARG SSH_KEY
# Make ssh dir
RUN mkdir /root/.ssh/
# Copy ssh
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa && \
chmod 0600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
# Add bitbuckets key
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN bundle install
COPY . ./
EXPOSE 80:80
CMD rails s -p 80 -b '0.0.0.0' -e qa
TL;DR: don't use rvm\rbenv within a container
the whole thing when using containers, is to bundle\package all the dependencies inside a container. for instance, if you need ruby 2.9 then use a docker image which has ruby 2.9 installed rather than using rvm[rbenv](https://github.com/rbenv/rbenv).
since you are using bundler, i will advise you to add rails gem to it, and let bundler manage the dependencies.
i assume that you care about the directory where rubygems are being installed for caching propose, and i see that you instruct bundler exactly what is the rubygem home directory
RUN bundle config set path 'vendor/bundle'
i am a newby in docker and I need an installation based on ubuntu of logstash.
I try the official logstash image and without success I can't run it so I decided to build my own installation based on my needs.
It works well but takes a lot of time to build it.
I wonder how can I improve (speed up) my building
This is my Dockerfile
FROM ubuntu:18.04
# RUN adduser --disabled-password --gecos "" ubuntu
# RUN usermod -aG sudo ubuntu
# RUN echo "ubuntu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN apt-get update && \
apt-get autoclean && \
apt-get autoremove
RUN echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
RUN apt-get install curl ca-certificates apt-utils wget apt-transport-https default-jre gnupg apt-transport-https software-properties-common -y
# RUN update-alternatives --config java
ENV LANG C.UTF-8
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64
ENV PATH $JAVA_HOME/bin:$PATH
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN apt update
RUN apt install ruby-full -y
RUN ruby --version
RUN apt install jruby -y
#install jruby (last version)
RUN jruby --version
RUN apt install logstash
#install plugins and bundles.
RUN cd /usr/share/logstash && gem install bundler
COPY logstash-pcap-test.conf /usr/share/logstash/
RUN mkdir /home/logstash/ && mkdir /home/logstash/traffic
COPY /traffic-example/* /home/logstash/traffic/
WORKDIR /usr/share/logstash
CMD ["/bin/bash","-c","bin/logstash -f logstash-pcap-test.conf --config.reload.automatic"]
And this is my docker-compose
version: "3"
services:
logstash_test:
build:
context: .
dockerfile: container/Dockerfile
image: logstash_test:latest
container_name: logstash_test
hostname: logstash_test
ports:
- 9600:9600
- 8089:8089
networks:
- elknetwork
networks:
elknetwork:
driver: bridge
Any thoughts?
I'm learning how to build a rails application using docker, and each time I attempt to run $ docker-compose build web I get the following error:
You must use Bundler 2 or greater with this lockfile.
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 20
This is my Dockerfile:
FROM ruby:2.5.1
ENV APP_HOME /usr/src/app
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
# Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs
RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
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 && \
apt-get update && apt-get install -y yarn
# SOURCE CODE
WORKDIR $APP_HOME
COPY . $APP_HOME/
RUN gem install bundler --version 2.0.2 --no-rdoc --no-ri
ADD Gemfile $APP_HOME/
ADD Gemfile.lock $APP_HOME/
RUN bundle install
RUN echo '--color' >> ~/.rspec
This is my docker-compose.yml file
version: '3'
services:
db:
image: postgres
webpacker:
build: .
command: bundle exec bin/webpack-dev-server
volumes:
- .:/fancyapp
ports:
- "8080:8080"
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/fancyapp
ports:
- "3000:3000"
depends_on:
- db
- webpacker
I'm a complete noob with docker and I honestly can't see what's wrong here.
I'm basing my implementation on this tutorial
Run the command gem list bundler, I guess your bundler version is less than version 2.
If so, run gem install bundler -v 2.0.2 to install the latest one.
You can run gem install --default bundler -v 2.0.2 to make it the default version to be used.
It seems like in your Gemfile.lock says that you use bundler with version higher than 2. In this case you you can use 2 ways:
decrease your local version
add to your docker file string gem install bundler (without version). It will install last bundler