Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symfony cli not setting port for dockerized postgresql db #472

Open
naturefund-falk opened this issue May 3, 2024 · 1 comment
Open

Comments

@naturefund-falk
Copy link

I created a new symfony (7.0.7) webapp, created an entity and wanted to run symfony console doctrine:database:create. Output:
An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at "127.0.0.1", port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
Apparently the port number is wrong here. As i understood the symfony command, it should detect the real port number of the postgres container and then call the doctrine:database:create command. But it seems this is not happening. Running 'symfony run printenv' does not print anything related to the database.

The database is running inside docker (status=unhealthy, but running 'pg_isready -U ${POSTGRES_USER:-app}' inside the container is running ok and no error messages in logs).
Docker 26.1.1 is installed in rootless mode on a debian 12 system.
Symfony cli version is 5.8.16.

@ebitkov
Copy link

ebitkov commented May 22, 2024

Kinda the same problem here, but with a MySQL Server.

I'm debugging this for a few days now, but coming to the conclusion, that the CLI is not detecting the Docker containers.

My System:

Symfony CLI version 5.8.15

Docker Desktop 4.29.0
Docker Compose version v2.26.1-desktop.1 (comes pre-packed with Docker Desktop)

Linux
Zorin OS 17.1 (Ubuntu-based)

My compose.yaml:

services:
    ###> doctrine/doctrine-bundle ###
    database:
        image: mysql:${MYSQL_VERSION:-8.0.33}
        volumes:
            - ./docker/provision/mysql/init:/docker-entrypoint-initdb.d
        environment:
            MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
            MYSQL_ROOT_PASSWORD: root
            MYSQL_PASSWORD: ${MYSQL_PASSWORD:-!ChangeMe!}
            MYSQL_USER: ${MYSQL_USER:-app}
        healthcheck:
            test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
            timeout: 5s
            retries: 10
        ports:
            -   "3306:3306"
    ###< doctrine/doctrine-bundle ###

I can connect to the database, but have to bind the port statically. Ideally you could just set "ports: [ 3306 ]" and the CLI would automatically pick up the port set by Docker, right?

Also the web profiler indicates, that Docker is not running:

image

Note, that in the latest version of Docker, the docker-compose command is deprecated and removed, only leaving docker compose (at least on my system). Could it be, that the Docker Compose API changed and the CLI is not able to detect the containers correctly?

Also: Docker Desktop sets the unix socket on unix:///home/user/.docker/desktop/docker.sock. Could this be a problem? Is there a way to manually configure the path to the socket? I couldn't find any documentation about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants