Docker Pit note psql:could not connect to server

Source: Internet
Author: User
Tags connection pooling postgresql psql unix domain socket docker ps

Recently, I've been running rails with Docker, and there are some pits, and here's a note.

First build Project:

docker-compose build

And then you start to get an error:

Psql:could not connect to server:no such file or directory
is the server running locally and accepting
Connections on Unix domain socket "/var/run/postgresql/.s.pgsql.5432"?

The error here is that the/var/run/postgresql/.s.pgsql.5432 file could not be found, but my local operation is no problem. So find Docker's example of Docker rails from getting started to practicing this book, here's the address: I found my database.yml file wrong. Mine is this:

default: &default  adapter: postgresql encoding: unicode`请输入代码` # For details on connection pooling,www.97yingyuan.org see Rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

the database target that Rails reads by default is localhost, and we need to specify the db of the capacitance manually. Similarly, the user name needs to be modified to coincide with the Postgres image reservation. Open the newly generated database.yml file. Replace with the following:

default: &default  adapter: postgresql  encoding: unicode  # For details on connection pooling, see Rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: postgres host: db

So run again docker-compose build , success build! And then run up again docker-compose up , the tragic error again:

Activerecord::nodatabaseerror (fatal:database "heroku_app_development" does not exist

Tip No database is created heroku_app_development , OK, then create one:

sudo docker ps#列出所有容器
sudo docker exec -it [container ID] /bin/bash#进入postgres
sudo su - postgres#切换到postgres用户, because this user has Createdb permissions
ceratedb heroku_app_development#heroku_app_development Creation Complete!

Again run docker-compose up , and error:

Migrations is pending. To resolve this issue, run:

    bin/rails db:migrate RAILS_ENV=development

Railser should be familiar with the database migration, into the Web container:
sudo docker exec -it [container ID] /bin/bash#进入web容器
rails db:migrate#迁移成功!

Docker Pit note psql:could not connect to server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.