So I have a clone of the java application, and an active couchbase database, everything on my local machine. When I run the java spring application, everything works well, the application will connect to the database.
On the other hand, I use the same project and database configurations using docker containers. But I can't seem to make them communicate, and when the app starts, I keep getting this exception:
java.net.ConnectException: Connection refused: localhost/127.0.0.1:8091
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:223)
at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:285)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:589)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:513)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:427)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:399)
at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:745)
I also created a docker network where I put the app and database.
Any idea why there is no connectivity ?
you try to connect to container's localhost
java.net.ConnectException: Connection refused:
localhost/127.0.0.1:8091
But you need to connect to another container. If you run docker container with argument --link mysql:mysql you need to specify into app configuration file connect to mysql instead of localhost of 127.0.0.1
Related
I am trying to run some integration tests in my Jenkins pipeline connecting to a mysql docker container. For some reason, we can't connect to it. We have checked that the credentials are right and that the port is exposed to the host:
mysql:5.6 0.0.0.0:3360->3306/tcp mysql
Our Jenkins runs in a host, it isn't a docker container.
I have inspect the container, and everything is the same as in my local environment, where I can connect to the container. This is the error I am getting:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Any idea what it could be?
Thanks in advance.
I have a problem with connecting to existing remote MSSQL database from inside of a docker container running in stack.
My application consists of three modules (backend, frontend and haproxy)
Backend module is written in Java (SpringBoot app) and it's also the one that needs to connect do remote MSSQL database (by remote I mean placed on different sever, separate of docker part).
I have the following docker compose file:
I start the stack by using following command:
docker stack deploy -c docker-compose.yml myapp
The result is, all containers are up and running, but spring app reports that connection to DB is timed out:
Server seems to be configured properly, I am able to access the host from container through telnet.
When running independently (even from docker container) backend app is able to connect to database with no problems, while stacked with docker-compose however it's unable to connect to the very same db.
I've also tried to provide db server IP instead of host name - no success.
Maybe setting up networks section in docker compose would do the trick?
UPDATE
Another thing you can do is to use host.docker.internal instead of the IP address of the database. This ONLY works on docker for windows or docker for mac.
Source: I want to connect from a container to a service on the host
OLD, only works when not in swarm mode
You need to specify that docker should use the same network as the host, you can do this in the following way:
version: '3'
services:
web-app:
build:
dockerfile: web-app/something
ports:
- 8080:8080
network_mode: "host"
Reference: Use host networking
It seems that the issue was caused by networks overlapping.
Adding network configured as show below, allowed either to connect to my remote database and keep my endpoints hidden:
networks:
backend:
ipam:
driver: default
config:
- subnet: 192.168.40.0/26
I have a docker swarm setup with services registered in an overlay network. Comunication between services is working fine however I get a "Connection refused" from one of my services that connects to an external DB. The service is a Java based application (spring boot).
The connection is defined with its IP (jdbc:mysql://192.168.130.141:3306/database?autoReconnect=true)
I have checked that I can ping the server from the container docker exec -it e093 ping 192.168.130.141 gives expected answer
I have rechecked (4 times) my credentials
I can connect to the DB from the host
Host is Ubuntu 16.04.4 LTS
I am running docker 18.03.0-ce and the exact error is
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151]
I'll skip the full stack trace here.
Any help would be greatly appreciated
--EDIT--
Let me clarify that the database is a Galera cluster and the IP I try to connect to is the load balancer (HAProxy) in front of it. I know the setup works as I have other applications connecting to the cluster in this matter as well as the service itself (when not in a docker container).
So, as far as I can tell, my connection informations are correct but it doesn't connect from inside docker services.
Can you show your docker-compose.yml? In the ports you have to expose the port that you need to access.
ports:
- 3306:3306
You can install telnet to test if the port is open using this commands inside the container
docker container ls
docker exec -it conainerid bash
apt-get update
apt-get install telnet
I am building a local Spring app to access the database I created on OpenShift at 127.2.xx.yy/eetom:3306. So I created this propery in Beans.xml.
<property name="url" value="jdbc:mysql://127.2.xx.yy:3306/eetom"/>
but I got exceptions such as
Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
and
The driver has not received any packets from the server
So I changed the ip to localhost and used OpenShift rhc to create port forwarding. And the rhc showed that the ip I put originally and the port are exactly used for port forwarding. That method workded.
Question:
What is the right way to access the mysql diectly without port forwarding?
Someone helped me on this before, it's from OpenShift: OpenShift does not support direct connectivity to an embedded database on non-scalable applications.
java.sql.SQLNonTransientConnectionException: java.net.ConnectException :
Error connecting to server localhost on port 1527 with message Connection refused: connect.
I am using Netbeans.
If I go to the Services Tab and rightclick Java DB and start Server it works fine.
How can I do this programmaticly at Runtime. I just need whatever method will start the Java DB Server.
Have a look at how to use JavaDB with a desktop application. They describe how to start it programmatically there.
You need to start the NetworkServerControl additional documentation can be found here
NetworkServerControl server = new NetworkServerControl(InetAddress.getByName("localhost"), port);