Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install gems from git in dockerized rails app

Please, help me with building my first docker image. My Gemfile contails:

gem 'webpacker', github: 'rails/webpacker'

Here is Dockerfile:

FROM ruby:2.4-alpine

...
ADD Gemfile $INSTALL_PATH/Gemfile
ADD Gemfile.lock $INSTALL_PATH/Gemfile.lock
RUN bundle install
ADD . $INSTALL_PATH
...

Docker and docker-compose:

Docker version 17.03.1-ce, build c6d412e
docker-compose version 1.13.0, build 1719ceb

When I run

docker build .

I receive errors:

Fetching https://github.com/rails/webpacker.git
sh: git: not found

Git error: command `git clone 'https://github.com/rails/webpacker.git'
"/usr/local/bundle/cache/bundler/git/webpacker-
61415c05b31197242a5fde705ba334f36321be12"
--bare --no-hardlinks --quiet` in directory /test_task has failed.

I guess, the reason is related with github source, because if I remove all gems with github source from Gemfile, then gems will be fetched correctly from rubygems repository

Upd: when I use ruby:2.4-slim instead of alpine linux as base image, then build completes without errors

like image 885
Slava Nikulin Avatar asked May 05 '17 17:05

Slava Nikulin


People also ask

Can I use Git in a Docker container?

Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.


1 Answers

It seems you don't have git inside the container. To install it on an Alpine image, you should add to your Dockerfile this:

FROM ruby:2.4-alpine
RUN apk update && apk add git
... the rest of your Dockerfile ...

Hope it helps.

like image 55
OscarAkaElvis Avatar answered Sep 20 '22 03:09

OscarAkaElvis