Docker:从Debian到Postgres的连接?

发布于 2025-01-26 06:12:31 字数 1368 浏览 2 评论 0原文

我正在尝试运行电子学习社区服务器(ECS) 在Docker-Compose系统上。此ECS需要安装Postgres-DB。因此,这是我的第一个尝试

docker-compose.yml

version: "3"
services:
  debian:
    container_name: debian_test
    build: './stuff'
    restart: on-failure
    command: ["sleep","infinity"]
    links:
       - db

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: example
    ports:
      - "5432:5432"

和suck/dockerfile:

FROM debian:stretch

RUN apt-get update && apt-get install -y \
mysql-common libpq5 libsqlite3-0 openssl libxml2 libxslt1.1 libssl1.0.2 libmariadbclient18 libevent-2.0-5 libevent-core-2.0-5 libevent-extra-2.0-5 libreadline7 apt-transport-https

所以我将debian放在第一个容器中,而在另一个容器中有postgres。现在,我进入了已安装ECS的Debian容器...

docker exec -it debian_test bash

...运行ECS。但是在这里我收到错误:

Called from /opt/ecs4/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
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"?

如何连接这两个容器?

最好的, 亚历克斯

I'm trying to run a E-learning community server (ECS)
https://www.freeit.de/en/campusconnect_ecs/index.html
on a docker-compose system. This ECS needs a postgres-DB to be installed. So this is my first try

docker-compose.yml

version: "3"
services:
  debian:
    container_name: debian_test
    build: './stuff'
    restart: on-failure
    command: ["sleep","infinity"]
    links:
       - db

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: example
    ports:
      - "5432:5432"

and stuff/Dockerfile:

FROM debian:stretch

RUN apt-get update && apt-get install -y \
mysql-common libpq5 libsqlite3-0 openssl libxml2 libxslt1.1 libssl1.0.2 libmariadbclient18 libevent-2.0-5 libevent-core-2.0-5 libevent-extra-2.0-5 libreadline7 apt-transport-https

So I have debian in the first container and postgres in the other container. Now I enter the debian container, where I have installed ECS...

docker exec -it debian_test bash

...run the ECS. But here I receive the error:

Called from /opt/ecs4/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
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"?

How is it possible to connect these two containers?

Best,
Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨的味道风的声音 2025-02-02 06:12:31

首先:数据库连接在哪里定义?仅在撰写文件中?通常,您应该至少在某处设置数据库服务器名称。

第二:检查容器是否在同一网络中运行?

docker inspect CONTAINER_ID OR NAME

本节是“ NetworkSettings” - > “网络”

First: Where is the database-connection defined? Only in the compose file? Normaly you should set at least the database-server-name somewhere.

Second: Check if the containers are running in the same network?

docker inspect CONTAINER_ID OR NAME

The section is "NetworkSettings" -> "Networks"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文