Reputation: 6669
Hi I am trying to adapt my-app to docker.
My app stack is
I created a Dockerfile
to create an image of my-app
FROM ruby:2.4
RUN apt-get update && apt-get install -y \
software-properties-common \
python-software-properties \
build-essential \
libpq-dev \
libxml2-dev libxslt1-dev \
libqt4-webkit libqt4-dev xvfb \
nodejs \
postgresql
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY Gemfile /usr/src/app
COPY Gemfile.lock /usr/src/app
RUN bundle install
ADD . /usr/src/app
COPY ./docker/docker-entrypoint.sh /usr/src/app/docker-entrypoint.sh
RUN chmod +x /usr/src/app/docker-entrypoint.sh
RUN bundle install
Then I created a docker-compose.yml
version: '3'
services:
app:
image: app_rails
entrypoint: ['/usr/src/app/docker-entrypoint.sh']
ports:
- "3000:3000"
depends_on:
- postgres
links:
- postgres
volumes:
- .:/usr/src/app
environment:
DATABASE_URL: postgres://postgres@postgres@postgres:5432/postgres?pool=5&encoding=utf-8
postgres:
image: postgres:9.5.8
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
And here is the script docker-entrypoint.sh
#!/bin/sh
set -e
host="$1"
echo "host: ${host}"
if [ "$#" -gt 0 ]; then shift; fi
until psql -h "$host" -U "postgres" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
rails db:create
rails db:migrate RAILS_ENV=development
bundle exec rails server -b 0.0.0.0
exec "$@"
and my database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
adapter: postgresql
database: app_development
pool: 5
timeout: 5000
url: postgres://postgres@postgres/postgres:5432
test:
adapter: postgresql
database: app_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: app_production
pool: 5
timeout: 5000
I am having trouble running the script
web_1 | connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
web_1 | Postgres is unavailable - sleeping
Since I am new to docker an advise will be wellcome
Upvotes: 0
Views: 587
Reputation: 8596
You're DATABASE_URL can't be localhost, it needs to be the name of service. It also needs username and password in there:
postgres://postgres:postgres@postgres/postgres
It doesn't need post since it uses the default. Here's examples of URL's: https://stackoverflow.com/a/20722229/749924
Upvotes: 2
Reputation: 1170
Try
chmod +x /usr/src/my-app/docker-entrypoint.sh
to ensure your entry point is an executable
Upvotes: 1