cqlsh to Cassandra “Unable to connect", in containers, on docker-machine VM - cassandra

We’re attempting to run Cassandra (2.2.0) in a container and cqlsh (5.0.1) in another container on a Mac. It works on a Linux laptop but fails to connect on a Mac (10.9.5). Failure on Mac (following worked on Linux) is:
# Start Cassandra in a Docker container
docker run --detach --name cassandra1 -p 9042:9042 poklet/cassandra
# Connect to Cassandra using cqlsh
docker run -it --rm --net container:cassandra1 poklet/cassandra cqlsh
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")})
docker run -it --rm --net container:cassandra1 poklet/cassandra cqlsh cassandra1
Connection error: ('Unable to connect to any servers', {'cassandra1': error(111, "Tried connecting to [('172.17.0.10', 9042)]. Last error: Connection refused")})
docker run -it --rm --net container:cassandra1 poklet/cassandra cqlsh 172.17.0.10
Connection error: ('Unable to connect to any servers', {'172.17.0.10': error(111, "Tried connecting to [('172.17.0.10', 9042)]. Last error: Connection refused")})
We wanted to verify whether the problem was specific to cqlsh, or simply a port problem.
Instead of trying to connect cqlsh to cassandra, we used curl to connect to a webserver on the same port (on the mac). We stopped the containers and:
# started a container with a webserver on port 9042:
docker run -it --name cassandra1 -p 9042:9042 ubuntu
python -m SimpleHTTPServer 9042
# and a container to represent “cqlsh”:
docker run -it --rm --net container:cassandra1 ubuntu /bin/bash
and were able to perform the following commands successfully on the “clqsh” container (curl localhost:9042, curl cassandra1:9042, curl 172.17.0.9:9042) to show that its not a port problem.
We think this is a cqlsh specific problem on a docker-machine VM.

Assuming that you have cassandra installed on your local machine.
Example:
$ docker-machine ip default
192.168.0.10
$ cqlsh 192.168.0.10

Related

Not able to run Cassandra locally using brew

I am trying to run Cassandra on my machine. Tying cqlsh gives me this error,
Connection error: ('Unable to connect to any servers', {'127.0.0.1:9042': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
Running cassandra -f hangs.
I installed cassandra using brew install cassandra.
Also I have done all of the followings:
Killed docker instance
Uninstall and reinstall Cassandra (deleted all the Cassandra data and filles from my machine)
Restarted my machine
Purged docker data
I don't know why still I am running into this. Running brew services list shows:
Name Status User Plist
cassandra started aanish /Users/aanish/Library/LaunchAgents/homebrew.mxcl.cassandra.plist
mysql stopped
mysql#5.7 started aanish /Users/aanish/Library/LaunchAgents/homebrew.mxcl.mysql#5.7.plist
postgresql stopped
The cqlsh connection error indicates that localhost is not listening on port 9042 (Cassandra's CQL client port). The most likely reason is that the Cassandra process is not running.
You can confirm whether the Java process is listening on port 9042 if you run the following command in a terminal:
$ sudo lsof -nPi -sTCP:LISTEN
You will need to review the system.log (typically in /var/log/cassandra) to figure out what is going on with Cassandra.
Note that if you set rpc_address in cassandra.yaml to the IP of your mac, you need to specify that address when you connect with cqlsh. For example:
$ cqlsh 10.1.2.3

Problem executing "minikube start" command

malik#malik:~$ minikube start
😄 minikube v1.12.0 on Ubuntu 18.04
✨ Using the docker driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🎉 minikube 1.12.1 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.12.1
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.18.3 preload ...
E0727 07:25:35.757871 14015 cache.go:63] save image to file "k8s.gcr.io/kube-apiserver:v1.18.3" -> "/home/malik/.minikube/cache/images/k8s.gcr.io/kube-apiserver_v1.18.3" failed: write: Get https://k8s.gcr.io/v2/kube-apiserver/blobs/sha256:83b4483280e5187b2801b449338d5755e5874ab80c44bf1ce615d258142e7c8b: dial tcp: lookup k8s.gcr.io: no such host
E0727 07:25:35.757643 14015 cache.go:63] save image to file "k8s.gcr.io/coredns:1.6.7" -> "/home/malik/.minikube/cache/images/k8s.gcr.io/coredns_1.6.7" failed: write: Get https://k8s.gcr.io/v2/coredns/blobs/sha256:c6568d217a0023041ef9f729e8836b19f863bcdb612bb3a329ebc165539f5a80: dial tcp: lookup k8s.gcr.io: no such host
E0727 07:25:35.757512 14015 cache.go:63] save image to file "k8s.gcr.io/kube-scheduler:v1.18.3" -> "/home/malik/.minikube/cache/images/k8s.gcr.io/kube-scheduler_v1.18.3" failed: write: Get https://k8s.gcr.io/v2/kube-scheduler/blobs/sha256:83b4483280e5187b2801b449338d5755e5874ab80c44bf1ce615d258142e7c8b: dial tcp: lookup k8s.gcr.io: no such host
E0727 07:26:22.529729 14015 cache.go:63] save image to file "kubernetesui/dashboard:v2.0.1" -> "/home/malik/.minikube/cache/images/kubernetesui/dashboard_v2.0.1" failed: nil image for kubernetesui/dashboard:v2.0.1: Get https://index.docker.io/v2/: dial tcp: lookup index.docker.io: no such host
E0727 07:26:22.544151 14015 cache.go:63] save image to file "kubernetesui/metrics-scraper:v1.0.4" -> "/home/malik/.minikube/cache/images/kubernetesui/metrics-scraper_v1.0.4" failed: nil image for kubernetesui/metrics-scraper:v1.0.4: Get https://index.docker.io/v2/: dial tcp: lookup index.docker.io: no such host
E0727 07:26:22.579102 14015 cache.go:63] save image to file "k8s.gcr.io/etcd:3.4.3-0" -> "/home/malik/.minikube/cache/images/k8s.gcr.io/etcd_3.4.3-0" failed: write: error calculating manifest: Get https://storage.googleapis.com/eu.artifacts.k8s-artifacts-prod.appspot.com/containers/images/sha256:303ce5db0e90dab1c5728ec70d21091201a23cdf8aeca70ab54943bbaaf0833f: dial tcp: lookup storage.googleapis.com: no such host
E0727 07:26:22.579102 14015 cache.go:63] save image to file "k8s.gcr.io/kube-controller-manager:v1.18.3" -> "/home/malik/.minikube/cache/images/k8s.gcr.io/kube-controller-manager_v1.18.3" failed: write: error calculating manifest: Get https://storage.googleapis.com/eu.artifacts.k8s-artifacts-prod.appspot.com/containers/images/sha256:da26705ccb4b5eb623a7cc42e566d21b0e23c1f59a0b4d6acac3fb810538c0d5: dial tcp: lookup storage.googleapis.com: no such host
E0727 07:26:22.579194 14015 cache.go:63] save image to file "k8s.gcr.io/kube-proxy:v1.18.3" -> "/home/malik/.minikube/cache/images/k8s.gcr.io/kube-proxy_v1.18.3" failed: write: error calculating manifest: Get https://storage.googleapis.com/eu.artifacts.k8s-artifacts-prod.appspot.com/containers/images/sha256:3439b7546f29bec22edd737bc0a5770ead18b5ee5ce0aea5af9047a554715f9f: dial tcp: lookup storage.googleapis.com: no such host
E0727 07:26:22.579229 14015 cache.go:63] save image to file "gcr.io/k8s-minikube/storage-provisioner:v1.8.1" -> "/home/malik/.minikube/cache/images/gcr.io/k8s-minikube/storage-provisioner_v1.8.1" failed: write: error calculating manifest: Get https://storage.googleapis.com/artifacts.k8s-minikube.appspot.com/containers/images/sha256:4689081edb103a9e8174bf23a255bfbe0b2d9ed82edc907abab6989d1c60f02c: dial tcp: lookup storage.googleapis.com: no such host
E0727 07:26:22.619544 14015 cache.go:172] Error downloading kic artifacts: failed to download kic base image or any fallback image
❗ Executing "docker container inspect minikube --format={{.State.Status}}" took an unusually long time: 5.369799649s
💡 Restarting the docker service may improve performance.
🤷 docker "minikube" container is missing, will recreate.
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
🤦 StartHost failed, but will try again: recreate: creating host: create: creating: create kic node: create container: docker run -d -t --privileged --security-opt seccomp=unconfined --tmpfs /tmp --tmpfs /run -v /lib/modules:/lib/modules:ro --hostname minikube --name minikube --label created_by.minikube.sigs.k8s.io=true --label name.minikube.sigs.k8s.io=minikube --label role.minikube.sigs.k8s.io= --label mode.minikube.sigs.k8s.io=minikube --volume minikube:/var --security-opt apparmor=unconfined --cpus=2 --memory=2200mb -e container=docker --expose 8443 --publish=127.0.0.1::8443 --publish=127.0.0.1::22 --publish=127.0.0.1::2376 --publish=127.0.0.1::5000 gcr.io/k8s-minikube/kicbase:v0.0.10#sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438: exit status 125
stdout:
stderr:
Unable to find image 'gcr.io/k8s-minikube/kicbase:v0.0.10#sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438' locally
docker: Error response from daemon: Get https://gcr.io/v2/k8s-minikube/kicbase/manifests/sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438: Get https://gcr.io/v2/token?scope=repository%3Ak8s-minikube%2Fkicbase%3Apull&service=gcr.io: net/http: request canceled (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
🤷 docker "minikube" container is missing, will recreate.
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
😿 Failed to start docker container. "minikube start" may fix it: recreate: creating host: create: creating: create kic node: create container: docker run -d -t --privileged --security-opt seccomp=unconfined --tmpfs /tmp --tmpfs /run -v /lib/modules:/lib/modules:ro --hostname minikube --name minikube --label created_by.minikube.sigs.k8s.io=true --label name.minikube.sigs.k8s.io=minikube --label role.minikube.sigs.k8s.io= --label mode.minikube.sigs.k8s.io=minikube --volume minikube:/var --security-opt apparmor=unconfined --cpus=2 --memory=2200mb -e container=docker --expose 8443 --publish=127.0.0.1::8443 --publish=127.0.0.1::22 --publish=127.0.0.1::2376 --publish=127.0.0.1::5000 gcr.io/k8s-minikube/kicbase:v0.0.10#sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438: exit status 125
stdout:
stderr:
Unable to find image 'gcr.io/k8s-minikube/kicbase:v0.0.10#sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438' locally
docker: Error response from daemon: Get https://gcr.io/v2/: dial tcp: lookup gcr.io: no such host.
See 'docker run --help'.
❌ [INVALID_PROXY_HOSTNAME] error provisioning host Failed to start host: recreate: creating host: create: creating: create kic node: create container: docker run -d -t --privileged --security-opt seccomp=unconfined --tmpfs /tmp --tmpfs /run -v /lib/modules:/lib/modules:ro --hostname minikube --name minikube --label created_by.minikube.sigs.k8s.io=true --label name.minikube.sigs.k8s.io=minikube --label role.minikube.sigs.k8s.io= --label mode.minikube.sigs.k8s.io=minikube --volume minikube:/var --security-opt apparmor=unconfined --cpus=2 --memory=2200mb -e container=docker --expose 8443 --publish=127.0.0.1::8443 --publish=127.0.0.1::22 --publish=127.0.0.1::2376 --publish=127.0.0.1::5000 gcr.io/k8s-minikube/kicbase:v0.0.10#sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438: exit status 125
stdout:
stderr:
Unable to find image 'gcr.io/k8s-minikube/kicbase:v0.0.10#sha256:f58e0c4662bac8a9b5dda7984b185bad8502ade5d9fa364bf2755d636ab51438' locally
docker: Error response from daemon: Get https://gcr.io/v2/: dial tcp: lookup gcr.io: no such host.
See 'docker run --help'.
💡 Suggestion: Verify that your HTTP_PROXY and HTTPS_PROXY environment variables are set correctly.
📘 Documentation: https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/
When I run the "minikube start" command the Docker fails to load the images that are needed as it is being used as the virtual machine manager by Minikube and Kubectl is providing the interface for Minikube to be used on the terminal. I executed commands and operations using the Virtualbox as well but no use. The version of Docker, Kubectl & Minikube is up-to-date.
I have tried installing Minikube and Kubectl several times using different packages and methods but useless
Please help me so that I can be able to start a cluster and make my PC a Worker Node and get going on the road of Cloud Computing Development
You might have a minikube VM that has an old version or/and minikube cannot connect to. You can try deleting the VM and/or wipe out ~/.minikube
$ minikube delete
$ rm -rf ~/.minikube
If that doesn't work then you have a problem with VirtualBox. Uninstall/Re-install
3 years ago, I spent a lot of time struggling with minikube even though it has been the official way to run kubernetes locally.
If you get stuck, i would suggest to have a KinD cluster up in few seconds by just running this script:
kind_version="v0.8.1"
kind_bin_path=/usr/local/bin/kind
if [ ! -f ${kind_bin_path} ]; then
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/${kind_version}/kind-$(uname)-amd64"
chmod +x ./kind
sudo mv ./kind ${kind_bin_path}
fi
cat <<EOF | kind create cluster --config -
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
# Now check
kubectl get nodes
# Congrats!
To customize more the cluster, check other YAML config here.
Good luck for whatever works for you.

Connection refused to Postgresql on docker

I'm trying to connect to postgres docker container via psycopg2, but i keep getting the same error.
I'm doing this on jupyter (docker container), i restart several times postgres container and i change postgresql.config listen_addresses = '*' to listen_addresses = 'localhost' and it's the same error.
This is the docker run command:
docker run --name postgres -e POSTGRES_PASSWORD=xxxxxxx -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
python
import psycopg2 as pg
connection = pg.connect("host=localhost dbname=easy_cleaning user=root")
I expect to connect, but i got this error:
----> 3 connection = pg.connect("host=localhost dbname=easy_cleaning user=root")
/opt/conda/lib/python3.7/site-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
124
125 dsn = _ext.make_dsn(dsn, **kwargs)
--> 126 conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
127 if cursor_factory is not None:
128 conn.cursor_factory = cursor_factory
OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
On your configuration, your container is not on localhost, Docker created a private IP to it. So you need to run:
docker inspect postgres
And look for IPAddress field to use in your connection as:
connection = pg.connect("host=<DOCKER_IP_ADDRESS> dbname=easy_cleaning user=root")
OR
You can use docker-compose to run your images as services and each service has it's name, which can be used as a hostname in your connections, like:
connection = pg.connect("host=postgres dbname=easy_cleaning user=root")
Read more here

DBeaver / PostgresSQL fails to connect to remote docker container

I'm trying to access a postgresql docker container through DBeaver, but I can't figure out how to make it work.
Running docker port db_1 returns:
5432/tcp -> 0.0.0.0:5432
So the port should be open to connections.
The postgresql.conf is set to
listen_addresses = '*'
Running docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' db_1 returns
172.19.0.2
When trying to connect to the database to either localhost / 127.0.0.1 / 172.19.0.2 / db_1 the Dbeaver log returns this:
2019-03-18 17:22:03.000 - Connect with 'jdbc:postgresql://db_1:5432/test' (postgres-jdbc-169919c23d5-77ac021a71307fee)
....
2019-03-18 17:22:14.815 - SSH INFO: SSH_MSG_SERVICE_ACCEPT received
2019-03-18 17:22:14.824 - SSH INFO: Authentications that can continue: password,keyboard-interactive
2019-03-18 17:22:14.825 - SSH INFO: Next authentication method: password
2019-03-18 17:22:18.432 - SSH INFO: Authentication succeeded (password).
2019-03-18 17:22:18.458 - Connection failed (postgres-jdbc-169919c23d5-77ac021a71307fee)
2019-03-18 17:22:18.459 - SSH INFO: Disconnecting from domain.com port 22
2019-03-18 17:22:18.461 - SSH INFO: Caught an exception, leaving main loop due to Socket closed
2019-03-18 17:22:18.514 - org.jkiss.dbeaver.model.exec.DBCConnectException: The connection attempt failed.
org.jkiss.dbeaver.model.exec.DBCConnectException: The connection attempt failed.
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:179)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.openConnection(PostgreDataSource.java:363)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.initializeRemoteInstance(PostgreDataSource.java:122)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.<init>(JDBCDataSource.java:100)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.<init>(JDBCDataSource.java:89)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.<init>(PostgreDataSource.java:80)
at org.jkiss.dbeaver.ext.postgresql.PostgreDataSourceProvider.openDataSource(PostgreDataSourceProvider.java:97)
at org.jkiss.dbeaver.registry.DataSourceDescriptor.connect(DataSourceDescriptor.java:770)
at org.jkiss.dbeaver.runtime.jobs.ConnectJob.run(ConnectJob.java:70)
at org.jkiss.dbeaver.ui.dialogs.connection.ConnectionWizard$ConnectionTester.run(ConnectionWizard.java:232)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:101)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.Driver$ConnectThread.getResult(Driver.java:405)
at org.postgresql.Driver.connect(Driver.java:263)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.lambda$0(JDBCDataSource.java:148)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:157)
... 11 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
at org.postgresql.core.PGStream.receiveChar(PGStream.java:306)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:405)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:94)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.access$100(Driver.java:57)
at org.postgresql.Driver$ConnectThread.run(Driver.java:364)
at java.lang.Thread.run(Thread.java:748)
Really clueless on how to make the connection work. The SSH tunnel obviously works, but the connection to the db fails. I have a spring boot application running in another container, and connecting that through the connection string jdbc:postgresql://db_1:5432/test works like a charm.
Any input on this? Could it be that 0.0.0.0 doesn't get mapped to the internal network somehow?
How are you exactly running your container, I suspect maybe you are missing to expose the ports? because I just tried running a postgres instance using the following command in PS:
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5433:5432 postgres
Mapping the default postgres container port 5432 to my local 5433 port (because I have a postgres installation locally and didn't want to run into some kind of port-interferance problem) and later on created a database by accessing the docker and running some psql commands as described on this answer and then accesed the DB from DBeaver
and everything worked fine! Hope this helps.

I can't connect to cassandra from nodejs app in docker container

I have a nodejs app inside a docker container (node:7.8.0) using 'bridge' network. I use the cassandra driver to connect with a cassandra server, but it raises timeout exception when initialize the connection:
Error: The host 172.16.210.101:9042 did not reply before timeout 12000 ms
at OperationTimedOutError.DriverError (node_modules/cassandra-driver /lib/errors.js:14:19)
at new OperationTimedOutError (node_modules/cassandra-driver/lib/errors.js:104:33)
at Connection.onTimeout (node_modules/cassandra-driver/lib/connection.js:645:20)
at Timeout._onTimeout (node_modules/cassandra-driver/lib/connection.js:620:10)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
From inside the container, I can ping the cassandra server and do a telnet connection.
Using 'host' network works, and executing the app in a "standard" environment too.
Any help is appreciate.
Ok, I found the solution.
The MTU of my host machine is 1450, and docker0 uses by default 1500. It produces an error.
So, I change the MTU for docker and it works.
I use a debian host and I followed next steps:
Copy the service file:
cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service
Then, edit the "ExecStart" line like this:
ExecStart=/usr/bin/dockerd -H fd:// --mtu=1400
Finally, restart docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
Source:
https://rahulait.wordpress.com/2016/02/28/modifying-default-mtu-for-docker-containers/

Resources