mardi 21 avril 2015

Docker seems to be migrating database on the server instead of migrating on RDS

I apologize if my question seems trivial but I am a total noob when it comes to deploying my rails app.

I'm trying to deploy my app using docker on elastic beanstalk. But the deployment fails on the db migration. I get this message: Docker container quit unexpectedly after launch: directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? Am I right thinking that docker is trying to connect locally to postgresql?

I don't see how to tell docker to connect to RDS as my database.yml file is already pointing at my rds database. Also here is my dockerfile:

FROM seapy/ruby:2.2.0

RUN apt-get update

# Install nodejs
RUN apt-get install -qq -y nodejs

# Intall software-properties-common for add-apt-repository
RUN apt-get install -qq -y software-properties-common

# Install Nginx.
RUN add-apt-repository -y ppa:nginx/stable
RUN apt-get update
RUN apt-get install -qq -y nginx
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
RUN chown -R www-data:www-data /var/lib/nginx

# Add default nginx config
ADD nginx-sites.conf /etc/nginx/sites-enabled/default

# Install foreman
RUN gem install foreman

# Install the latest postgresql lib for pg gem
RUN echo "deb http://ift.tt/1gJzaoz trusty-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
    apt-get update && \
    DEBIAN_FRONTEND=noninteractive \
    apt-get install -y --force-yes libpq-dev
# Install paperclip dependencies
RUN apt-get install -qq -y  ImageMagick    

# Copy gemfile and bundle in temporary
WORKDIR /tmp
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock
RUN bundle install -j 4

# Copy app and precompile assets
RUN mkdir /app
ADD . /app
WORKDIR /app
ENV RAILS_ENV production
RUN bundle exec rake assets:precompile

# Nginx
ADD nginx-sites.conf /etc/nginx/sites-enabled/default

EXPOSE 80
CMD bundle exec rake db:migrate && foreman start -f Procfile

And my database.yml file:

production:
  adapter: postgresql
  encoding: utf-8
  database: <%= ENV['RDS_DATABASE_NAME'] %>
  username: <%= ENV['RDS_DATABASE_USERNAME'] %>
  password: <%= ENV['RDS_DATABASE_PASSWORD'] %>
  hostname: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

Many thanks in advance for your help but I couldn't find a relevant fix yet,

Best,

Thomas




Aucun commentaire:

Enregistrer un commentaire