docker-library / cassandra

Docker Official Image packaging for Cassandra
Apache License 2.0
263 stars 281 forks source link

socket.gaierror: [Errno -2] Name or service not known #210

Closed KabDeveloper closed 4 years ago

KabDeveloper commented 4 years ago

Description

I am trying to launch cassandra container using docker-compose, but stay recieving this error message:

cassandra-server_1  | Connection error: ('Unable to connect to any servers', 
{'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})

Notice that I get it working well when I use directly this command line:

$ docker run -d --name=c1 cassandra:3.11.6

And then I ssh the container, and using CQLSH command normaly.

I know it is related to the networking, and I tried everything I was able to without success !

Here is my docker-compose file:

version: '3.4'

services:
  cassandra-server:
    image: 'cassandra:3.11.6'
    network_mode: host
    expose:
      - 7000
      - 7001
      - 7199
      - 9042
      - 9142
    ports:
      - '9042:9042'
    command: bash -c 'cqlsh'

I am using the network mode: Host after switching from bridge mode.

Here is my other configuration with bridge mode:

version: '3.4'

networks:
  app-tier:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.16.238.0/24

services:
  cassandra-server:
    image: 'cassandra:3.11.6'
    networks:
      - aapp-tier
    expose:
      - 7000
      - 7001
      - 7199
      - 9042
      - 9142
    ports:
      - '9042:9042'
    command: bash -c 'cqlsh'

Unfortunately I get the same error message for both configurations.

Steps to reproduce the issue:

docker run -it --rm --network app-tier cassandra:latest cqlsh --username ca ssandra --password cassandra cassandra-servers

  cassandra-server:
    image: 'cassandra:latest'
    networks:
      - app-tier
    ports:
      - '9042:9042'
    environment:
      - CASSANDRA_SEEDS=cassandra
      - CASSANDRA_PASSWORD_SEEDER=yes
      - CASSANDRA_PASSWORD=cassandra
    volumes:
      - 'cassandra:/bitnami'

Describe the results you received:

This command:

docker run -it --rm --network app-tier bitnami/cassandra:latest cqlsh --username ca
ssandra --password cassandra cassandra-servers

Result:

Traceback (most recent call last):
  File "/opt/bitnami/cassandra/bin/cqlsh.py", line 2443, in <module>
    main(*read_options(sys.argv[1:], os.environ))
  File "/opt/bitnami/cassandra/bin/cqlsh.py", line 2421, in main
    encoding=options.encoding)
  File "/opt/bitnami/cassandra/bin/cqlsh.py", line 485, in __init__
    load_balancing_policy=WhiteListRoundRobinPolicy([self.hostname]),
  File "/opt/bitnami/cassandra/bin/../lib/cassandra-driver-internal-only-3.11.0-bb96859b.zip/cassandra-driver-3.11.0-bb96859b/cassandra/policies.py", line
417, in __init__
socket.gaierror: [Errno -2] Name or service not known

or this error when I ssh the container and launch CQLSH command:

cassandra-server_1  | Connection error: ('Unable to connect to any servers', 
{'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})

Describe the results you expected:

Expect a working Cassandra Server

Version

Client:
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.7
 Git commit:        74b1e89e8a
 Built:             Wed Jul 31 15:18:18 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea838
  Built:            Wed Nov 13 07:28:45 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
Client:
 Debug Mode: false

Server:
 Containers: 2
  Running: 1
  Paused: 0
  Stopped: 1
 Images: 7
 Server Version: 19.03.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.14.154-boot2docker
 Operating System: Boot2Docker 19.03.5 (TCL 10.1)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 989.5MiB
 Name: default
 ID: VOY2:F3HL:T3RR:5RYH:RTGG:6HOS:EPZ3:WIYL:J22K:UVAD:ZHEQ:TDRW
 Docker Root Dir: /mnt/sda1/var/lib/docker
 Debug Mode: false
 Username: progwebinfo
 Registry: https://index.docker.io/v1/
 Labels:
  provider=virtualbox
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine
docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.0.2q  20 Nov 2018

Additional environment details (AWS, VirtualBox, Docker for MAC, physical, etc.):

I am on Windows 7 24bit Using Docker Toolbox

wglambert commented 4 years ago

Your docker-compose.yml files aren't working because of the command: bash -c 'cqlsh' https://docs.docker.com/engine/reference/run/#cmd-default-command-or-options Essentially our entrypoint will be skipped and go straight to cqlsh. Just like if you start the image with bash as the command, the entrypoint will skip initializing the database and you'll have immediate access to bash in the container

$ docker run -it --rm cassandra bash
root@2c01d55f467d:/# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  2.5  0.0  20176  3800 pts/0    Ss   14:51   0:00 bash
root         11  0.0  0.0  36072  3292 pts/0    R+   14:51   0:00 ps aux

But if you do encounter further issues it would most likely be due to the environment Docker is running under; Boot2Docker/Windows and I would suggest trying those resources first https://github.com/boot2docker/boot2docker https://github.com/docker/for-win

KabDeveloper commented 4 years ago

I finally was succeeded to make it working I had to set rpc_address to 0.0.0.0

LvChengbin commented 3 years ago

I encounter the same problem while the rpc_address is 0.0.0.0.