6

I have a Sinatra app that works fine in Docker:

# Image
FROM ruby:2.3.3
RUN apt-get update && \
    apt-get install -y net-tools


# Install app
ENV APP_HOME /app
ENV HOME /root
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
COPY Gemfile* $APP_HOME/
RUN bundle install
COPY . $APP_HOME


# Configure App
ENV LANG en_US.UTF-8
ENV RACK_ENV production

EXPOSE 9292


# run the application
CMD ["bundle", "exec", "rackup"]

But when I try to add Redis:

# Redis
RUN         apt-get update && apt-get install -y redis-server
EXPOSE      6379
CMD         ["/usr/bin/redis-server"]

Redis does not seem to start.

So, what is a good way to add Redis to a Ruby (FROM ruby:2.3.3) Docker container?

B Seven
  • 44,484
  • 66
  • 240
  • 385

2 Answers2

5

Split this into two containers. You can use docker-compose to bring them up on a common network. E.g. here's a sample docker-compose.yml:

version: '2'

services:
  sinatraapp:
    image: sinatraapp:latest
    ports:
    - 9292:9292
  redis:
    image: redis:latest

The above can include more options for your environment, and assumes your image name is sinatraapp:latest, change that to the image you built. You'll also need to update your sinatra app to call redis by the hostname redis instead of localhost. Then run docker-compose up -d to start the two services.

BMitch
  • 231,797
  • 42
  • 475
  • 450
2

There can be only one CMD command in your Dockerfile. Moreover what you want to do is a little more complex than you might think.

P.S. The above are stackoverflow links.

Community
  • 1
  • 1
Alkis Kalogeris
  • 17,044
  • 15
  • 59
  • 113