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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I saw that it is easier and better to do it this way.
For the future searchers, the redis key won't work in this case. See stackoverflow.com/a/42380642/336920
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.

2 Comments

It seems that the "Docker way" would be to have 2 containers. Simpler and easier.
Yes that's the correct and easiest way if you don't have any serious complications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.