最近在用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 #进入postgres
sudo 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的更多相关文章

  1. EntityFramework CodeFirst SQLServer转Oracle踩坑笔记

    接着在Oracle中使用Entity Framework 6 CodeFirst这篇博文,正在将项目从SQLServer 2012转至Oracle 11g,目前为止遇到的问题在此记录下. SQL Se ...

  2. ubuntu 下安装docker 踩坑记录

    ubuntu 下安装docker 踩坑记录 # Setp : 移除旧版本Docker sudo apt-get remove docker docker-engine docker.io # Step ...

  3. CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记

    CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记 cas服务器的搭建 导出证书(1和2步骤是找了课程,随便写了一下存记录,不过对于自己测试不投入使用应该不影响) C:\Users\D ...

  4. ASP.NET Web 应用 Docker踩坑历程——续

    ASP.NET Web 应用 Docker踩坑历程发表后,也开始使用Docker了,然而发布的过程比较痛苦,经常发生下图的事情: 据说是nuget包还原时发生错误 百度了半天也找不到解决的方法,而发生 ...

  5. 问题解决: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 ...

  6. “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 ...

  7. 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 ...

  8. 问题解决: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 ...

  9. 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 ...

随机推荐

  1. CentOS 5.6怎么安装MongoDB数据库?

    1. 下载Linux版本的 MongoDB 数据库 到官方的下载页面下载mongodb的Linux版本,32位还是64位根据自己的情况自行选择 http://www.mongodb.org/downl ...

  2. linux flushing file system caches

    We may drop the file system caches on Linux to free up memory for applications. Kernels 2.6.16 and n ...

  3. 自学youku_web

    仿youku架构 数据库设计 管理员 注册 登录 上传视频 删除视频 发布公告 普通用户 注册 登录 充会员 查看视频 下载免费视频 下载收费视频 查看观影记录 查看公告 思路 class Field ...

  4. 太阳地球月亮运行动画(使用@keyframes)

    闲来无事的demo <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  5. avalon.js的循环操作在表格中的应用

    avalon.js的循环操作在表格中的应用 一个JAVA开发,因为做的门户系统中,数据的展示加载的速度很影响使用效果,想到的是尽量少的请求后台,然后接触到了avalon,看介绍这是一个很轻很轻的MVV ...

  6. Python的静态方法和类方法

    Python中使用@staticmethod这个装饰器让方法变为静态方法 一:定义 @staticmethod: 首先它是一个装饰器,被装饰的方法不需要隐含的参数,对象和对象的实例都可以调用静态方法 ...

  7. 基于mybatis设计简单OA系统问题2

    1.<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <fm ...

  8. 【Effective C++ 读书笔记】导读 Introduction

    学习程序语言根本大法是一回事,学习如何以某种语言设计并实现高效程序则是另一回事. 一组明智选择并精心设计的classes.functions.templates可使程序编写容易.直观.高效.并且远离错 ...

  9. 【PHP】Maximum execution time of 30 seconds exceeded解决办法

    Maximum execution time of 30 seconds exceeded,今天把这个错误的解决方案总结一下: 简单总结一下解决办法: 报错一:内存超限,具体报错语句忘了,简单说一下解 ...

  10. ThinkPHP路由去掉隐藏URL中的index.php

    官方默认的.htaccess文件 <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On ...