My GCP ES service is port forwarded to localhost:9200 of my machine. I am able to log ingest from the local machine.
I have created JAVA script to do the same task and It is also running fine when I am running local
Now, I have created docker Image of that Java project using dockerFile and when I am creating a container, then I am getting the following error
Connect to localhost:9200 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
Docker command :
docker run -it --net="host" gcplogingest:latest mvn -f BEATLe/pom.xml test -Dcomponent=detect -DtestSuite=CommonXML/Detect_loginjectionGCP
Note :
I have tried using --network="host" but I am still getting the same error.
Please suggest.
Have you tried removing --net=host and then use in your docker host.docker.internal instead 127.0.0.1?
Consider that your host localhost should be different than your docker localhost, and once you get that removing network=host, you need to access from docker to
host.docker.internal:9200
Related
I have got a container with Jenkins. I am trying to run tests pipeline inside this container. Tests uses Testcontainers. I am struggling with error:
18:36:15.560 [testcontainers-ryuk] WARN org.testcontainers.utility.RyukResourceReaper - Cannot connect to Ryuk at 172.17.0.1:55592
java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.base/java.net.Socket.connect(Socket.java:609)
at org.testcontainers.utility.RyukResourceReaper.lambda$null$0(RyukResourceReaper.java:92)
at org.rnorth.ducttape.ratelimits.RateLimiter.doWhenReady(RateLimiter.java:27)
at org.testcontainers.utility.RyukResourceReaper.lambda$maybeStart$1(RyukResourceReaper.java:88)
at java.base/java.lang.Thread.run(Thread.java:829)
Jenkins container was run by command
docker run -v /var/run/docker.sock:/var/run/docker.sock -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 5000:5000 -d --restart always <img>
I've tried to run Jenkins container with --network="host" but same effect.
When I am running those tests directly on my local machine by mvn clean verify, tests passed and this error didn't occur.
EDIT:
I've changed network to bridge (--network="bridge") for Jenkins container. In test I used explicite network bridge:
new GenericContainer("mongodb:1..").withNetworkMode("bridge")...
Ryuk container is created (I can see three containers on my host docker - jenkins, mongo, ryuk) and when I run docker network inspect bridge I can see three containerers are attatched to it. But when I am trying connect to Ryuk container using gateway (172.17.0.1) from Jenkins container using telenet it is NOT possible. But when I am using Ryuk IP (172.17.0.2) instead of gateway's IP I can connect. Then I've create other container on my host and tryied to connect to it form Jenkins container via gateway's IP - could do it.
SOLUTION
Just run Jenkins container with -v /var/run/docker.sock.raw:/var/run/docker.sock instead of -v /var/run/docker.sock:/var/run/docker.sock.
Thanks #Kevin Wittek!
As mentioned in one of the comments, this originates from an issue in Testcontainers for Java regarding an upstream change in Docker Desktop (see this issue).
The current workaround for Mac is to mount the raw socket when creating the container:
-v /var/run/docker.sock.raw:/var/run/docker.sock
After installing docker on a windows server i got the following error when pulling a image with docker run hello-world command:
Error response from daemon: Get https://hub.docker.com/v2/: dial tcp
52.6.16.15:443: connectex: No connection could be made because the target machine actively refused it.
The problem was that the proxy was blocking the request.
After some headaches, i finally got how to setup up proxy for docker on windows server from the right guide:
Using powershell in elevated mode:
Set environment variable to HTTP_PROXY environment variable
[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://username:password#proxy:port/", [EnvironmentVariableTarget]::Machine)
May not need to specify credentials, if your proxy don't require it.
Restart docker
Restart-Service docker
Now it should run:
docker run hello-world
im learning docker and go now
but i got the problem when i docker run with this
docker run --rm -p 8080:8080/tcp --env-file .env my-project:latest
here are some of my .env code. i use docker desktop on windows, is it not possible to run docker on localhost in windows?
DB_HOST=127.0.0.1
DB_USERNAME=root
DB_NAME=mydbs
DB_PASS=root123
AUTH_GEN_URL=https://api.learning.mydbs.id
anyone have a clue? any answer would be appreciated
thank youu
The problem is that when you spin up the container it tries to connect to 127.0.0.1:3306 within the container and not the host, hence you are getting the error as connection refused since nothing is running on port 3306 at localhost in your container.
For Windows and Mac this can easily be fixed by using host.docker.internal instead of 127.0.0.1. This ensures that the service running inside your container correctly connects to the MySQL instance running on the host machine.
For Linux it's even more simple as all you have to do is pass --network="host" option to the docker run command
I'm running locally a gremlin-client container and a gremlin-server container in 2 separate containers. I'm starting the following like so:
docker network create -o com.docker.network.bridge.enable_icc=true hacker
docker run --network hacker -p 8182:8182 tinkerpop/gremlin-server:3.4
docker run --network hacker -it tinkerpop/gremlin-console
When I try and connect to the remote server from the client like so:
:remote connect tinkerpop.server conf/remote.yaml
I get the following error:
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:8182
Why is this? I tried to share the network, but still doesn't work. Any ideas? The port is forwarded and matching what is in the remote.yaml file.
Edit
I got it working by modifying the host in the conf file on the client to read as host.docker.internal
I got it working by modifying the host in the conf file on the client to read as host.docker.internal
I'm having trouble initializing a Cassandra database in a docker container.
Here's my Dockerfile :
FROM cassandra
COPY ./createTable.cql /tmp/createTable.cql
RUN cqlsh -f /tmp/createTable.cql
When I do docker build . -t cassandra, I get an error at 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")})
But the same commands work fine when I do it outside a Docker container.
Why is the connection refused ? If I'm doing it wrong, how can I initialize my
database ?
Thanks for any help or advice.
The RUN is executed when you build the container, not when the container executes.
You need to write custom script that will start Cassandra (same as in original container - look into Cassandra's Dockerfile), then wait until it starts, and only after that - execute commands via cqlsh.
cqlsh command needs the hostname where the Cassandra is running if the hostname is not provided it will take the localhost (127.0.0.1) as the hostname.
In your case, it's taking localhost as hostname, looks like your Cassandra is running outside of the container because of that reason it is working fine when you run from outside and failing from inside container.
Passing the hostname to cqlsh should resolve your problem when your run it inside container also.
cqlsh <hostname or ip> -f /tmp/createTable.cql