docker 踩坑笔记之 psql: could not connect to server
最近在用docker跑rails,也遇到了一些坑,这里记录一下。
首先build项目:
docker-compose build
然后就开始报错了:
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"?
这里报错是说找不到 /var/run/postgresql/.s.PGSQL.5432 文件,但我本地运行是没问题的。于是去找docker从入门到实践这本书的docker rails 例子, 地址在这里:发现我的database.yml文件不对。我的是这样的:
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 } %>
Rails 默认读取的数据库目标是 localhost ,我们需要手动指定容器的 db 。同样的,还需要把用户名修改成和 postgres 镜像预定的一致。 打开最新生成的 database.yml 文件。用以下内容替换:
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
这样再运行docker-compose build,成功build! 然后再跑起来docker-compose up,悲剧的又报错了:
ActiveRecord::NoDatabaseError (FATAL: database "heroku_app_development" does not exist
提示没有创建heroku_app_development数据库,OK,那就创建一个:
sudo docker ps #列出所有容器sudo docker exec -it [container ID] /bin/bash #进入postgressudo su - postgres #切换到postgres用户,因为这个用户有createdb权限ceratedb heroku_app_development #heroku_app_development 创建完成!
再运行docker-compose up,又报错:
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=development
railser应该很熟悉,数据库迁移,进入web容器:sudo docker exec -it [container ID] /bin/bash #进入web容器rails db:migrate #迁移成功!
docker 踩坑笔记之 psql: could not connect to server的更多相关文章
- EntityFramework CodeFirst SQLServer转Oracle踩坑笔记
接着在Oracle中使用Entity Framework 6 CodeFirst这篇博文,正在将项目从SQLServer 2012转至Oracle 11g,目前为止遇到的问题在此记录下. SQL Se ...
- ubuntu 下安装docker 踩坑记录
ubuntu 下安装docker 踩坑记录 # Setp : 移除旧版本Docker sudo apt-get remove docker docker-engine docker.io # Step ...
- CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记
CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记 cas服务器的搭建 导出证书(1和2步骤是找了课程,随便写了一下存记录,不过对于自己测试不投入使用应该不影响) C:\Users\D ...
- ASP.NET Web 应用 Docker踩坑历程——续
ASP.NET Web 应用 Docker踩坑历程发表后,也开始使用Docker了,然而发布的过程比较痛苦,经常发生下图的事情: 据说是nuget包还原时发生错误 百度了半天也找不到解决的方法,而发生 ...
- 问题解决: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"?
错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...
- “psql: could not connect to server: Connection refused” Error when connecting to remote database
问题: I am trying to connect to a postgres database installed in a remote server using the following c ...
- psql: could not connect to server: No such file or directory&&PGHOST
由于环境变量 PGHOST配置不当引起的 postgres@pgdb-> psql psql: could not connect to server: No such file or dire ...
- 问题解决: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"?
错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...
- psql: could not connect to server: No such file or directory
postgresql报错: psql: could not connect to server: No such file or directory Is the server run ...
随机推荐
- Centos6.4环境下DNS服务器的搭建
DNS服务器搭建很繁琐吗?给你个简单的招吧! 配置域主服务器 阶段: 1.在bind的主配置文件中添加该域 2.在/var/named中创建该域的zone文件 3.编辑zone文件,添加需要的信息 4 ...
- 2018.8.5 Bootstrap 使用
Bootstrap的环境搭建 <link rel="stylesheet" type="text/css" href="css/bootstra ...
- 剑指offer39 平衡二叉树
剑指上用了指针传递,这里用的引用传递 class Solution { public: bool IsBalanced_Solution(TreeNode* pRoot) { ; return IsB ...
- ES6 extends继承及super使用读书笔记
extends 继承 extends 实现子类的继承 super() 表示父类的构造函数, 子类必须在 constructor中调用父类的方法,负责会报错. 子类的 this 是父类构造出来的, 再在 ...
- 爬虫学习(十五)——json解析
json与jsonpath 对象{}:jsonobject 对象:对象在js中表现为{}括起来的内容,数据结构为{key:value,key:value...}键值对的结构,在面向对象的结构中,key ...
- 利用sysbench进行MySQL OLTP基准测试
Preface In order to know clearly about the real performance threshold of database server,we ...
- Docker迁移学习及其他
起因: 有在一台服务器A上通过docker搭建git服务,由于某些原因需要将其迁移到另一台服务器B. 过程: 最终采用方式: 首先通过docker ps(-a) 查看目标容器,然后通过commit命令 ...
- javaScript的闭包 js变量作用域
js的闭包 js的变量作用域: var a=90; //定义一个全局变量 function test(){ a=123; //使用外层的 a变量 } test(); document.write(&q ...
- 1016-02-首页17-添加转发微博控件-计算转发配图的 Frame-------打印出 被转发微博的模型
说明:HWStatus为微博模型,_retweeted_status 为返回的数据( 一条微博模型)里面的一个属性,_retweeted_status 不为空表示此微博是否转发了其他微博._retwe ...
- POJ:3684-Physics Experiment(弹性碰撞)
Physics Experiment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3392 Accepted: 1177 Sp ...