Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run bundle install with a Dockerfile file

I want to use docker to deploy a rails application. I followed the official tutorial to do:

https://docs.docker.com/compose/rails/

But it seems I am not lucky.

My Dockerfile

FROM ruby:2.2.2

RUN apt-get update -qq && apt-get install -y build-essential

# for mysql
RUN apt-get install -y mysql-client libmysqlclient-dev

# for a JS runtime
RUN apt-get install -y nodejs

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile $APP_HOME/Gemfile
ADD Gemfile.lock $APP_HOME/Gemfile.lock

RUN bundle install

ADD . $APP_HOME

My docker-compose.yml

db:
  image: mysql
  ports:
    - "3306:3306"
web:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  volumes:
    - .:/myapp
  ports:
    - "3000:3000"
  links:
    - db

After I run docker-compose build, it shows:

...
Fetching git://github.com/guard/guard-test.git
/usr/local/bundle/gems/bundler-1.10.6/lib/bundler/ui/shell.rb:94:in `[]': invalid byte sequence in US-ASCII (ArgumentError)
    from /usr/local/bundle/gems/bundler-1.10.6/lib/bundler/ui/shell.rb:94:in `strip_leading_spaces'
    from /usr/local/bundle/gems/bundler-1.10.6/lib/bundler/ui/shell.rb:99:in `word_wrap'
    from /usr/local/bundle/gems/bundler-1.10.6/lib/bundler/ui/shell.rb:85:in `tell_me'
    from /usr/local/bundle/gems/bundler-1.10.6/lib/bundler/ui/shell.rb:31:in `error'
    from /usr/local/bundle/gems/bundler-1.10.6/lib/bundler/friendly_errors.rb:12:in `rescue in with_friendly_errors'
    from /usr/local/bundle/gems/bundler-1.10.6/lib/bundler/friendly_errors.rb:7:in `with_friendly_errors'
    from /usr/local/bundle/gems/bundler-1.10.6/bin/bundle:18:in `<top (required)>'
    from /usr/local/bundle/bin/bundle:23:in `load'
    from /usr/local/bundle/bin/bundle:23:in `<main>'
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 1

What's wrong?

like image 461
scho Avatar asked Nov 06 '15 03:11

scho


People also ask

How do I install something in Dockerfile?

To install packages in a docker container, the packages should be defined in the Dockerfile. If you want to install packages in the Container, use the RUN statement followed by exact download command . You can update the Dockerfile with latest list of packages at anytime and build again to create new image out of it.

How do I install a bundle installed?

Install BundlerSelect Tools | Bundler | Install Bundler from the main menu. Press Ctrl twice and execute the gem install bundler command in the invoked popup. Open the RubyMine terminal emulator and execute the gem install bundler command.

How do I run an existing Dockerfile?

Follow these steps: Use docker ps to get the name of the existing container. Use the command docker exec -it <container name> /bin/bash to get a bash shell in the container. Or directly use docker exec -it <container name> <command> to execute whatever command you specify in the container.


1 Answers

Looking at a similar error in "bundle install error “invalid byte sequence in US-ASCII (ArgumentError)”", one option is to ad to the Dockerfile:

export LANG=C.UTF-8

See this Dockerfile for instance.

# Install required packages
# LANG=C.UTF-8 line is needed for ondrej/php5 repository
RUN \
    export LANG=C.UTF-8 && \
    ...
like image 82
VonC Avatar answered Sep 19 '22 14:09

VonC