3

I can't get the connection between my PostgreSQL database from my Rails app which is running in a Docker container working.

The application just works fine, I just can't connect to the database.

docker-compose.yml:

services:
    app:
        build:
            context: .
            dockerfile: app.Dockerfile
        container_name: application_instance
        command: bash -c "bundle exec puma -C config/puma.rb"
        volumes:             
            - .:/app
            - node-modules:/app/node_modules
            - public:/app/public
        depends_on:
            - database
            - redis
        env_file:
            - .env
    database:
        image: postgres
        container_name: database_instance
        restart: always
        volumes:      
            - db_data:/var/lib/postgresql/data
        ports:
            - "5432:5432"
        env_file:
            - .env
        environment: 
            POSTGRES_USER: ${POSTGRES_USER}
            POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
            POSTGRES_DB: ${POSTGRES_PRODUCTION_DB}
    nginx:
        build:
            context: .
            dockerfile: nginx.Dockerfile
        depends_on:
            - app
        volumes:
            - public:/app/public
        ports:
            - "80:80"
    redis:
        image: redis
        container_name: redis_instance
        ports:
            - "6379:6379"
    sidekiq:
        container_name: sidekiq_instance
        build:
            context: .
            dockerfile: app.Dockerfile
        depends_on:
            - redis
            - database
        command: bundle exec sidekiq
        volumes:
            - .:/app
        env_file:
            - .env
volumes:
    db_data:
    node-modules:
    public:

If I try to connect via DBeaver I get the following message:

DBeaver error

Any idea what's going wrong here? The port should be exposed on my local machine. I also tried with the IP of the container, but then I get a timeout exception.

1
  • What is the ${POSTGRES_PRODUCTION_DB} variable referring to? Commented Jul 4, 2021 at 18:45

2 Answers 2

4

This is because you most likely have postgres running locally on your machine (port 5432) and also on a docker (port 5432). Dbeaver wants to connect to database on your local machine, than on docker.

Any solution I figure out is to temporary stop/turn of your local postgres service (on Windows: Task manager -> Services -> (postgres service) -> stop).

I was also struggling with issue.

Sign up to request clarification or add additional context in comments.

Comments

1

I removed the Database name in DBeaver connection configuration and it worked

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.