How to bind the microservice locally in Eureka without docker host name? - java

In my local environment, I am trying to bind a microservice by up it locally. But instead of bind it with the computer username it bind as below.
UP (1) - host.docker.internal:mySampleMicroService:8096
but it should bind with computer name instead of host.docker.internal part.Thought this due to docker install in my computer, then uninstall it and checked it, but the issues was same
even with docker it doesnot show any image(just check it with 'docker image ls' command)
How can I bind the locally up service with my machine name in NETFLIX EUREKA?

Related

How connect to db when running Dockerfile?

I have a spring boot app that connects fine to my PostgreSQL server running locally in Desktop Docker.
Than I wrote a simple Dockerfile to run my app in container. Container starts but can't connect to my db server with error message:
Connection to localhost:5432 refused.
Why and how to fix this?
To access localhost from inside a docker container you can use the IP of your computer. Localhost or 127.0.0.0 donsen't work.
Use docker compose to connect the two docker containers.
https://docs.docker.com/compose/
On this page you can see an example on how to connect to containers using docker compose:
https://dev.to/mozartted/docker-networking--how-to-connect-multiple-containers-7fl
If they are on seperate Docker networks, use:
docker.host.internal
This connects to the Docker host machine. So if your PostgreSQL instance is exposed on 5432, docker.host.internal will route to that instance through the host from other containers.
Alternatively, set them up in the same network using docker compose or by creating a network and attaching both containers to them. They can then communicate with container name.
https://docs.docker.com/engine/reference/commandline/network_create/

Docker container shows no ports, can find IP but need both to connect to Java application

So I'm fairly new to Docker, only been using it for a day or two and recently pulled this https://hub.docker.com/r/ncbi/blast
Which is an image that has a set of commands to get information from a database. I have the Desktop version of Docker for windows and manage to get the image to pop up just fine. It shows up in my images,
I run the image via the desktop app. Give it the name "Test", see it's running using the "docker ps". I get it's IP just fine but see there are no ports.
I've heard that it might be connected to my local host which is why no ports show up but still where would I go to find my host port then and or just change the port? A java program/application I'm making is supposed to connect to this using IP and Port but I can't find the port. Any help would be appreciated, thank you again.
You have to include -p flag in your docker run command to expose ports for your application.
-d options runs docker container in the background.
For e.g. In Docker Run Command
docker run -p 8080:8080 -d ncbi/blast:latest

Accessing docker API from container

I am trying to build an application that can control dockers containers hosted on Docker for windows.
The application is built on top of docker-java library and it works fine.
I tried to host this application on docker itself. Hosting was OK. The issue is that, when the application tries to connect to tcp://localhost:2375 in order to access docker's api, the connection fails.
This is obviously because localhost within the container is not anymore refering to the actual host where Docker for Windows is installed.
So I used the explicit IP address to access docker's api from the container (tcp://192.168.0.10:2375), the connection was also refused!
I stopped the firewall, yet the issue was still there.
I searched for it, then I realized that I have to define "hosts" configuration variable to make docker's api accessable using the host's explicit IP address.
But when I tried to set the "hosts" configuration variable, docker said:
"hosts": Cannot be used in Docker for Windows
So does it mean that there is no way on Docker for Windows to host a container that can access its api?
Though I am not quite familiar with Docker on Windows, I found some introductions on docker website. Just try below.
I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON HOST.
But I strongly suggest you give Docker on Windows up.
Edited: 2018-9-5 19:55
Using host.docker.internal to access the host as comment suggested below.

Google compute instance is not accessible with external ip and port

I created a google compute instance on https://console.cloud.google.com/compute/instances
After that I deployed a jar file embedded jetty server running on port 8082. I execute the jar file with java -jar command.
In VPC network I add a firewall rule to open port 8082. Now if I try to access the google instance at port 8082 in web browser I am getting connection refused error. Below is the external ip address with port
http://35.184.211.81:8082
I don't know why above external ip is not working. If I open cloud shell and open web preview on port 8082 then I am able to access my web application on port 8082 below is the url
https://8082-dot-3144491-dot-devshell.appspot.com
It looks confusing. Above adress is showing that my application is deployed on google cloud instance but it is not accessible using external ip.
I solved above issue by myself.
The problem was that I was using google cloud shell to deploy my application. I run the java -jar command in google cloud shell. I don't know why changes made or program executed in google cloud shell are temporary so that's the reason my application wasn't accessible on external IP.
I connected my instance using SSH, run the jar file and then my application is accessible on external IP with port. In https://console.cloud.google.com there is an option to connect the instance with SSH so i use that option.

How to connect to machine ip address & port via grails app

I'm running MacOS 10.6 with the default settings for my machine with Internet Sharing turned on.
What needs to be configured to allow access to my machine's grails/jetty instance on a specific port?
I can do 'http://localhost/' as well as 'http://192.x.x.x/' but if I were to set my grails app to run on a specific port, I can't access it with: 'http://192.x.x.x:8081/'.
The browser can't establish a connection with this address from my own machine and I know that I need to establish an accessible port in some config file.
I used to be able to do this prior to an upgrade from the last version of the OS but it's been so long I don't remember what I did the last time.
NOTE: I can use 'grails run-app -Dserver.port=' to specify a port number for jetty to run my grails application but that still doesn't allow my machine to be accessible by ip address & port number.
grails run-app -Dserver.port=<port number>
run-app Runs a grails app using the default Jetty container. The default http port is 8080. This can be customised by appending -Dserver.port= to the command line
See the grails website for more details.

Categories