M
M
Messi2020-10-05 11:27:52
PHP
Messi, 2020-10-05 11:27:52

Can't connect to Clickhouse from a container?

There is docker-compose with clickhouse:

clickhouse:
        container_name: 'clickhouse'
        image: yandex/clickhouse-server:latest
        ports:
            - "8123:8123"
            - "9000:9000"
        volumes:
            - ./data/clickhouse/data:/var/lib/clickhouse
        networks:
            - lemp

    php:
        container_name: 'php'
        image: nm-service:php7.4-fpm
        build:
            context: ./php
            dockerfile: Dockerfile
        networks:
          - lemp

    nginx:
        container_name: 'nginx'
        image: nginx:1.19-alpine
        ports:
            - "80:80"
        volumes:
            - ./nginx.conf:/etc/nginx/conf.d/default.conf
        links:
            - php
        networks:
          - lemp


When I open localhost:8123 127.0.0.1:8123 in the browser , I get an Ok response. And I can connect to clickhouse via PHPStorm.

But if I make a request via php, for example the library https://github.com/smi2/phpClickHouse

$db = new ClickHouseDB\Client([
    'host' => 'localhost', (или 127.0.0.1)
    'port' => '8123',
    'username' => 'default',
    'password' => ''
]);
$db->ping();


I always get the error Failed to connect to 127.0.0.1 (or localhost) port 18123: Connection refused'

Why is that, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-10-05
@FitTech

why are you trying to connect to the localhost from the container?
host => clickhouse
port => 8123

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question