我正在尝试在 Symfony 和 Docker 中连接我的 PostgreSql 数据库并收到错误:
docker-compose.yml
services:
db:
image: postgres:${POSTGRES_VERSION:-12}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-my_db}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-root}
POSTGRES_USER: ${POSTGRES_USER:-root}
volumes:
- $PWD/postgres-data:/var/lib/postgresql/data:rw
profiles:
- db-in-docker
ports:
- "5432:5432"
networks:
- symfony
Run Code Online (Sandbox Code Playgroud)
和.env.dev.local
DATABASE_URL="postgresql://root:root@host.docker.internal:5432/my_db?serverVersion=12&charset=utf8"
Run Code Online (Sandbox Code Playgroud)
SQLSTATE[08006] [7] 无法连接到服务器:连接被拒绝
Run Code Online (Sandbox Code Playgroud)Is the server running on host "host.docker.internal" (192.168.65.2) and accepting TCP/IP connections on port 5432?
我埃文编辑了我的 /etc/hosts 文件以将此主机连接到127.0.0.1
由于这是在我的 Docker 主机上运行的 Postgres 数据库,因此我使用的是 host.docker.internal,它映射到 Mac 或 Windows 上的主机 IP,使用 127.0.0.1 或 localhost 将导致代码尝试连接到同一个容器运行代码,该代码没有运行数据库。
怎么解决这个问题呢?
我的 Docker 容器不断重新启动,并出现以下错误:
Run Code Online (Sandbox Code Playgroud)Operation not supported: AH00023: Couldn't create the mpm-accept mutex (95)Operation not supported: could not create accept mutex
我在网上尝试了一些解决方案,包括platform: linux/amd64切换 docker restart 等......
这个解决方案对我不起作用。
但是我无法编辑文件,此处httpd.conf提供了解决方案,因为我无法访问 docker 映像来执行此操作,因为它不断重新启动。
现在有人如何超越这个错误吗?我在Mac上M1。
Dockerfile:
FROM 242425.a.a.eu-central-1.amazonaws.com/app-php:7.4
ARG COMPOSER_TOKEN
ENV COMPOSER_TOKEN=${COMPOSER_TOKEN}
ARG GITHUB_OAUTH_TOKEN
ENV GITHUB_OAUTH_TOKEN=${GITHUB_OAUTH_TOKEN}
ARG ENVIRONMENT=""
ENV ENVIRONMENT=${ENVIRONMENT}
RUN apt-get --yes update && apt-get --yes --no-install-recommends install supervisor
RUN if [ "${ENVIRONMENT}" = "local" ]; \
then pecl install xdebug && docker-php-ext-enable xdebug; \
fi …Run Code Online (Sandbox Code Playgroud)