Accessing docker API from container - java

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.

Related

Setup windows based SQL connection from Docker container?

A few of our database connections are configured to require windows authentication. I am trying to setup a docker container with a java application which should be able to query those databases. However, I keep getting the following error:
Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
I am not sure if this is even doable - setting up windows auth from within docker container. Has anybody done it?
FYI - I am using docker for Windows
I believe you need to set up gMSA for this to work. The context is that Windows containers don't get domain-joined. With that, they don't get a computer account to talk to the domain, neither you can use a domain account to authenticate. gMSA solves that, but requires that you configure it with the container host (also referred to as gMSA v1) or K8s (also referred to as gMSA v2).
Here's the documentation on how gMSA works: https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/manage-serviceaccounts

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

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?

Accessing Google Cloud VM Instance Tomcat using External IP

I am trying to access my Tomcat HomePage which is inside my Google Cloud VM Instance with External IP address 35.189.85.127 and Internal IP 10.154.0.2. On my local machine, in my browser I tried http://35.189.85.127 and http://35.189.85.127:8080 but got error
The connection has timed out. The server at 35.189.85.127 is taking too long to respond.
I have seen all the questions and replies on stackoverflow regarding this question but still I found no clear solution.
The steps that I've done so far:
I have setup a Google Cloud VM instance in Compute Engine. I am using Windows Server 2016 as the image.
Using RDP I log on to Windows Server.
I successfully installed Java 1.7 and Tomcat 7 on Windows Server.
I tested Java and Tomcat 7, both are working fine i.e. I open browser and type localhost:8080 and it shows Tomcat HomePage.
I replaced localhost with my VM Instance Internal IP i.e. 10.154.0.2:8080 and it again correctly shows Tomcat HomePage.
Now I try to access Tomcat HomePage using my VM Instance External IP (Static) 35.189.85.127 but in my browser I get error
The connection has timed out. The server at 35.189.85.127 is taking too long to respond.
Faced the same issue today.
Noticed from your question that you're using an Windows environment.
On Windows
Be sure that the Windows Firewall is properly configured to allow traffic under the ports you need (or deactivate it).
On GCP
Under "VPC Network/Firewall Rules", create a new firewall rule and configure as below:
Firewall Rule Parameters (image)
Or, you have the option to check the "Allow HTTP traffic" option under the Instance Configuration menu and edit Tomcat's server.xml to startup at port 80, as described here:
Change Tomcat Port Tutorial # StackOverflow
Option1: If it's just tomcat. GCP offers a click to launch Tomcat instance with an external IP. You can SSH and also have a temp tomcat username and password to manage any of your deployments.
https://console.cloud.google.com/launcher/details/click-to-deploy-images/tomcat
Option 2:
If you wish to have a Google Cloud VM instance in Compute Engine.
You will need to setup security groups and assign it to your instance.
Eg. Define rules to Open Tomcat port 8080(or any) externally / range. Assign that group/rule to your VM instance.
There are many options available, it all depends on how you wish to organize things. You could create a VPC and add your instances there or keep them under the same subnet or have them accessible externally etc.

Not able to connect localhost with system ip

I have deployed my java web application using apache tomcact in my system through Eclipse. I can access the same page with
https://localhost:8080/Home.jsp
as well
https://mysystemip:8080/Home.jsp
But the same page is not able to connect
https://mysystemip:8080/Home.jsp over the network through other systems. Previously it was working and now not. What issue causing this ?
Your Tomcat server is only bound to your local network interface. You need to bind it to all interfaces for it to be available.
There is already a solution (Can't access Tomcat using IP address):
Add address="0.0.0.0" to Connector string

Spring : How to remove localhost from url

I am working on some project for that using spring 3.2.0. Whenever I run project it looks like
http://IpAddressWithPortNo.com/myprojectName.com/
IpAddressWithPortNo = localhost : 8080
I want to hide localhost:8080 or ip address.
Is there any method available to map this ip to my project?
http://myprojectName.com
I am using apache tomcat 7.0 and fedora 17.
The solution doesn't involve configuring Spring, but the hosts file of your operating system. On Ubuntu, it is found at /etc/hosts, I'm not sure if its the same for Fedora, but it should be.
You just need to add a line in the hosts file that looks like the following:
127.0.0.1 myprojectName.com
That's it. You then access the myprojectName.com address in your browser and it will look at your localhost, behind the scenes.
The above solution works if you only need name resolution for your local machine.
If you'd like to expand to your local or external network, the answer is less trivial:
for your local network, you need to register a custom domain on your network DNS server (see this and this for more information); if you have a network administrator, direct this requirement to him, explaining that you want to expose your local ip through a custom domain name
if you want to expose this name to the entire internet, you have to register the custom domain to a DNS registration service (you can find free DNS services as well, unfortunately I haven't used any lately and dyndns.org doesn't provide free dns service anymore, try searching free dns service on google and lookup some reviews)
The :8080 will go if you configure Tomcat to respond on port 80, or https on port 443.
You can use any host name that resolves to your network address. For instance if your machine name on the local network is athena.mycompany.com then http://athena.mycompany.com/myProjectName should work fine - but only within the local network.
To get to http://myprojectName.com you will need to configure a firewall/router to forward an incoming request (presumably from the Internet) to your machine. Internal access will likely not resolve this URL.
Gabriel has just posted an answer that should work from your machine, but other machines within your intranet would also require entries to map that name to your machine.
For doing exactly what you want, you need to configure apache tomcat to listen on port 80 and tell your operating system that myproject.com resolves to localhost.
To resolve myproject.com to localhost, add the following to your /etc/hosts file:
127.0.0.1 myproject.com
To change the port number to 80, open /usr/share/tomcat7/confserver.xml or /etc/tomcat7/server.xml (whichever applies to your system) and change Connector port = 8080 to Connector port = 80.

Categories