Postgresql容器未在docker-compose文件中运行-为什么这样做? [英] Postgresql Container is not running in docker-compose file - Why is this?

查看:84
本文介绍了Postgresql容器未在docker-compose文件中运行-为什么这样做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清为什么我收到有关Postgresql未在我的项目中运行的错误的原因。
它不是通过Flask连接的,也不是当我尝试使用命令
docker-compose run postgres bash 然后通过<$ c通过bash访问它时$ c> psql 返回错误:

I am trying to figure out why I am getting an error about postgresql not running in my project. It is not connecting through Flask, nor when I try to access it through bash using the command docker-compose run postgres bash then psql returns the error:

bash-5.0# psql
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"?

我尝试运行-force-recreate 并丢弃所有废弃的孤儿容器,但这似乎没有效果。同样,我通过卸载本地文件并删除所有文件来确保它不会干扰我的本地postgresql安装。

I tried running --force-recreate and to drop all abandoned orphan containers but this has not seemed to work. Similarly, I made sure it does not interfere with my local postgresql installation by uninstalling the local one and removing all files. I am pretty stumped on this.

这是我的docker-compose文件:

Here is my docker-compose file:

version: "3"

services:

  webapp:
    build: .
    container_name: webapp
    ports:
      - "5000:5000"

  postgres:
    image: postgres:11-alpine
    container_name: postgres
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=tmp
      - POSTGRES_USER=tmp
      - POSTGRES_PASSWORD=tmp_password
    volumes:  # Persist the db data
      - database-data:/var/lib/postgresql/data


volumes:
  database-data:

我们将不胜感激。

推荐答案

因此,在尝试设置邮件服务器后,我发现了问题。基本上,我已经在本地计算机上安装了postgresql,然后将其移至docker时却忘记了将其卸载。当我从本地计算机上卸载postgresql时,docker db现在可以工作了。

So I figured out the issue after trying to set up a mail server. Basically, I had installed postgresql on the local machine and then when I moved it to docker I forgot to uninstall it. When I uninstalled postgresql from the local machine the docker db now works.

这篇关于Postgresql容器未在docker-compose文件中运行-为什么这样做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆