I start my Rails 6 app as Docker containers, but when it starts the Rails server, it keeps giving the error:
warning Integrity check: System parameters don't match
website_1 | error Integrity check failed
website_1 | error Found 1 errors.
website_1 |
website_1 |
website_1 | ========================================
website_1 | Your Yarn packages are out of date!
website_1 | Please run `yarn install --check-files` to update.
website_1 | ========================================
website_1 |
website_1 |
website_1 | To disable this check, please change `check_yarn_integrity`
website_1 | to `false` in your webpacker config file (config/webpacker.yml).
So why is this not working? I have that command in the Dockerfile and also that check is disabled in webpacker.yml.
I build it with docker-compose up --build and then it doesn't seem to give errors.
When I start it with docker-compose up, it will return the erorr when the Rails server is started. Here are the relevant files:
Dockerfile:
FROM ruby:2.6.5-slim
LABEL maintainer="John van Arkelen <johnvanarkelen#fastmail.com>"
RUN apt-get update -qq && apt-get install -y curl build-essential libpq-dev postgresql postgresql-contrib
RUN mkdir /app
RUN mkdir -p /usr/local/nvm
WORKDIR /app
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v
ENV BUNDLE_PATH /gems
RUN gem install bundler -v 2.0.2
COPY Gemfile Gemfile.lock package.json yarn.lock ./
RUN bundle install
RUN npm install -g yarn
COPY . /app
RUN yarn install --check-files
webpacker.yml:
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: false
docker-compose.yml:
version: '2'
services:
postgres:
image: 'postgres:10.3-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password123
POSTGRES_DB: qd_development
env_file:
- '.env'
redis:
image: 'redis:4.0-alpine'
command: redis-server --requirepass password123
volumes:
- 'redis:/data'
website:
depends_on:
- 'postgres'
- 'redis'
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
ports:
- '3000:3000'
volumes:
- '.:/app'
- gem_cache:/gems
environment:
DATABASE_HOST: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password123
POSTGRES_DB: qd_development
env_file:
- '.env'
volumes:
redis:
postgres:
gem_cache:
It seems to me like you are building your app correctly in the image in the /app directory. But afterward in your docker-compose you mount a local volume over your built /app directory, thereby losing your built /app folder contents.
Try removing the mounted volume '.:/app'.
In your docker-compose.yml, you can also do this to avoid rebuilding everytime time. Then, you can just do docker-compose up
command: bash -c "bundle install && yarn install --check-files && bundle exec rails s -p 3000 -b '0.0.0.0'"
Related
This error message appears to 3 images in composed docker container.
exec /usr/bin/entrypoint.sh: no such file or directory
All images related to Ruby execution of services
Sidekiq, Webpack runned by Ruby executable and Web(rails) services
I have tried change every execution to run loading de Gemfile environment using bundle exec, but nothing worked.
Dockerfile
FROM ruby:2.6.6
RUN apt-get update -qq \
&& apt-get install -y curl build-essential libpq-dev postgresql \
nodejs postgresql-client &&\
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
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 nodejs yarn
ADD . /app
WORKDIR /app
RUN gem install bundler:2.3.22
RUN bundle install
RUN yarn install --check-files
RUN gem install foreman
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 80
CMD ["bash"]
docker-compose.yml
version: '3.3'
services:
db:
image: postgres
ports:
- 5423:5432
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: *****
redis:
image: redis
ports:
- "6379:6379"
volumes:
- 'redis:/data'
depends_on:
- db
webpack:
build: .
command: sh -c 'rm -rf public/packs/* || true && bin/webpack-dev-server --host 0.0.0.0 --port 3035 -w'
volumes:
- .:/app
- /app/node_modules
ports:
- "3035:3035"
depends_on:
- db
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && rails s -b 0.0.0.0 -p 80"
volumes:
- .:/app
ports:
- "80:80"
depends_on:
- db
- redis
- webpack
- chrome
env_file: .env_docker
environment:
RAILS_ENV: development
RAILS_MAX_THREADS: 5
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- .:/app
depends_on:
- db
- redis
env_file: .env_docker
environment:
RAILS_MAX_THREADS: 5
chrome:
image: selenium/standalone-chrome
ports:
- "4444:4444"
volumes:
- /dev/shm:/dev/shm
depends_on:
- db
- redis
- webpack
- sidekiq
volumes:
redis:
postgres:
Equal to entrypoint.sh exec: #: not found but not resolved
I really want to change my Debian development OS to Windows and work only with containers, not looking to Linux or WSL alternatives
I have a very basic rails & docker app that I want to add Angular to, to handle all my frontend javascript. However, I can't seem to get Angular to work. I installed Angular via webpacker. As of now I only have the hello-angular files that come standard with rails 6 and webpack.
Dockerfile
FROM ruby:2.6
# Prerequisites
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 && apt-get update -q && apt-get install -y nodejs yarn cron
# Cache Gems
WORKDIR /tmp
ADD Gemfile .
ADD Gemfile.lock .
RUN bundle install
# Copy App
WORKDIR /usr/bcb/app
ADD . /usr/bcb/app
# Precompile assets
RUN bin/yarn install
RUN bin/rails assets:precompile
# Expose port 3000 to other containers (Note: not external devices such as our workstation)
ENV PORT 3000
EXPOSE $PORT
# Run the built in Rails server (puma)
CMD ./docker-entrypoint.sh
# clean up APT
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
docker-compose.yml
version: '3.3'
volumes:
dbdata:
driver: local
services:
nginx:
image: nginx
ports:
- '8080:80'
volumes:
- ./nginx/vhost.development.conf:/etc/nginx/conf.d/default.conf
restart: always
depends_on:
- web
db:
image: postgres:11
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=devdb
volumes:
- dbdata:/var/lib/postgresql/data/pgdata
web:
build: . # Builds the image from Dockerfile
environment:
WEBPACK_DEV_SERVER_HOST: webpack_dev_server
links:
- webpack_dev_server
environment:
- RAILS_ENV=development
- RACK_ENV=development
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=devdb
volumes:
- .:/usr/bcb/app
depends_on:
- db
webpack_dev_server:
image: bcbapp_web
command: ./bin/webpack-dev-server
environment:
NODE_ENV: development
RAILS_ENV: development
WEBPACK_DEV_SERVER_HOST: 0.0.0.0
volumes:
- .:/usr/bcb/app
ports:
- "3035:3035"
docker-entrypoint.sh
rm -f tmp/pids/server*.pid
bin/rails server -b 0.0.0.0 -p $PORT --pid tmp/pids/server.`hostname`.pid
bundle exec rake db:migrate RAILS_ENV=$environment 2>/dev/null || bundle exec rake db:create db:migrate
Here is my github repo:
[1]: https://github.com/zacwillis/bcb
What am I missing?
I'm probably doing something very wrong, but I'll ask here just in case since I can't find it. Basically, I have no problem running my docker image when I'm on my pc and I just do "Docker-compose run..." from within the ruby app directory. However, when I push the image to the docker-hub, I want to pull that image on my ubuntu server to then build that image. The problem is that when I do so, I don't really have access to the ruby app, the gemfile or anything so it doens't work at all...
This was my error :
Step 10/23 : COPY Gemfile /myapp/Gemfile COPY failed: stat /var/lib/docker/tmp/docker-builder296802662/Gemfile: no such file or directory
My Dockerfile :
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
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-get update -qq && apt-get install -y nodejs yarn netcat libpq-dev nano tzdata apt-transport-https
RUN apt-get clean autoclean
RUN rm -rf /var/lib/apt /var/lib/dpkg /var/lib/cacbe /var/lib/log
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile Gemfile.lock /myapp/
RUN bundle install
COPY . .
RUN rm -Rf node_modules/
RUN rm yarn.lock
RUN spring stop
RUN rails webpacker:install
RUN yarn install
RUN yarn upgrade
RUN yarn install --check-files
EXPOSE 3000
# Running the startup script before starting the server
ENTRYPOINT ["sh", "./config/docker/startup.sh"]
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
My docker-compose :
services:
db:
image: mysql:latest
restart: always
command: --default-authentication-plugin=mysql_native_password
# volumes:
# - ./tmp/db:/var/lib/postgresql/data
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
MYSQL_USERNAME: root
MYSQL_PASSWORD: root
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
links:
- db
environment:
DB_USER: root
DB_NAME: test
DB_PASSWORD: root
DB_HOST: db
DB_PORT: 3306
RAILS_ENV: development
How am I supposed to make it so that on my ubuntu server I can simply pull the image from my repo, build and run it?
Thank you very much.
P.S. I also always get "Your Yarn packages are out of date!"...
If you've pushed your application images to Docker Hub, you need to, all in the web service:
Add the image: name of your Docker Hub image
Remove the build: section
Delete the volumes: that overwrite the image's code
Delete the command: overriding the image's CMD (consider adding the rm -f server.pid command to your startup.sh entrypoint script)
Delete the archaic links: setting
This leaves you with:
version: '3.8'
services:
db: *as_in_the_question
web:
image: 'myname/web:20200622'
ports:
- "3000:3000"
depends_on:
- db
environment:
DB_USER: root
DB_NAME: test
DB_PASSWORD: root
DB_HOST: db
DB_PORT: 3306
RAILS_ENV: development
On the remote system you need to copy only the docker-compose.yml file, and you should be able to run docker-compose up to start it; it will pull the Docker Hub image and run it.
On the local system, if you have both a build: and an image: setting, docker-compose build will tag the image with the name you specify, and docker-compose push will push the built image.
Getting this error when inserting values in Model through rails console .
"Mongo::Error::NoServerAvailable: No server is available matching
preference: # using server_selection_timeout=30 and local_threshold=
0.015 "
Both containers are running fine, but Rails not able to connect mongodb .
I have only one Dockerfile.
My docker-compose.yml file contents are:
version: '2'
services:
mongo:
image: mongo:3.0
command: mongod --smallfiles --quiet
environment:
- RAILS_ENV=production
- RACK_ENV=production
ports:
- "27017:27017"
app:
depends_on:
- 'mongo'
# - 'redis'
build: .
ports:
- '3000:3000'
volumes:
- '.:/app'
command: rails s -b '0.0.0.0'
env_file:
- '.env'
volumes:
mongo:
My Dockerfile :
FROM ruby:2.3.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
ENV APP_HOME /app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile* $APP_HOME/
RUN bundle install
ADD . $APP_HOME
Did you use mongo(same as the container name mentioned in docker-compose.yml) as your host in mongoid.yml?
I'm trying to use docker to push my existing rails project to a docker container.
I'm using postgres database.
When I did $> docker-compose up
I get following error in the logs.
web_1 | /docker-entrypoint.sh: line 99: exec: bundle: not found
app_web_1 exited with code 127
-
# Dockerfile
FROM ruby:2.2.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN gem install bundler
RUN bundle install
ADD . /myapp
FROM postgres:9.4
#FROM library/postgres
ENV POSTGRES_USER my-user-name
ENV POSTGRES_PASSWORD ''
ENV POSTGRES_DB app-database-name
-
# docker-compose.yml
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
You don't need two instruction in your Dockerfile, just use docker-compose for overwrite postgres enviroments images.
You can try this:
# Dockerfile
FROM ruby:2.2.3
# Update ubuntu and deps
RUN apt-get update -qq && apt-get install -y build-essential
# Install postgres dep
RUN apt-get install -y libpq-dev
# Install nokogiri dep
RUN apt-get install -y libxml2-dev libxslt1-dev
# Install JS runtime
RUN apt-get install -y nodejs
ENV APP_HOME /app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile* $APP_HOME/
# Install api deps
RUN bundle install --jobs 4
ADD . $APP_HOME
Now in your docker-compose.yml (I use v1 version) you can try that:
postgres:
image: postgres
environment:
POSTGRES_USER: my-user-name
POSTGRES_PASSWORD: ''
POSTGRES_DB: app-database-name
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -b '0.0.0.0'"
environment:
PORT: 3000
DATABASE_URL: 'postgres://postgres:#postgres:5432/postgres'
ports:
- '3000:3000'
link:
- db
volumes:
- .:/app