Can I reach docker started services via internal url? - docker

I'm running applications using docker containers. I run it with docker-compose. For example there is arangodb dependency:
arangodb:
image: localartifactiory/arangodb:3.2.5
volumes_from:
- arangodb_data
ports:
- 8530:8529
environment:
- ARANGO_ROOT_PASSWORD=admin
I can reach the service with http://localhost:8530, but I can't reach it using service name http://arangodb:8530 or http://arangodb:8529 in browser, still it looks like my application connects to this db by http://arangodb:8529 address.
Can you please tell me if it is possible to reach my service using service-based-url from browser or is it internal docker address that can be reached only inside containers?

The service name url is available due to the embedded DNS server in user-defined networks. This DNS server is only used to resolve DNS requests for containers that are part of the network.
Check Query docker embedded dns from host to see how to resolve DNS names using the embedded DNS server

To access service externally (from the browser) you need to use IP_ADDRESS of the host machine. Host machine means Windows/Ubuntu/ Mac, actual machine address.
To access service internally from one container to another then you can use container name (e.g. http://arangodb:8529).
let me know if you need any further details.

Related

How to Make Docker Use Specific IP Address for Browser Access from the Host

I'm using docker for building both UI and some backend microservices, and using Spring Zuul as the Proxy to pass Restful API calls from UI to the downstream microservices. My UI project needs to specify an IP address in the JS file before the build, and the Zuul project also needs to specify the IP addresses for the downstream microservices. So that after starting the containers, I can access my application using my docker machine IP http://192.168.10.1/myapp and the restful API calls in the browser network tab will be http://192.168.10.1/mymicroservices/getProduct, etc.
I can set all the IPs to my docker machine IP and build them without issues. However for my colleagues located in other countries, their docker machine IP will be different. How can I make docker use a specific IP, for example, 192.168.10.50, which I can set in the UI project and Zuul Proxy project, so that the docker IP will be the same for everyone, regardless of what their actual docker machine IP is?
What I've tried:
I've tried port forwarding in VirtualBox. It works for the UI, however the restful API calls failed.
I also tried the solution mentioned in this post:
Assign static IP to Docker container
However I can't access the services from the browser using the container IP address.
Do you have any better ideas? Thank you!
first of to clarify couple things,
If you are doin docker run ..... then you just starting container in your docker which is installed on the host machine. And there now way docker can change ip of your host machine. Thus if your other services are running somewhere else they will have to know something about docker host machine, ip or dns name.
so basically docker does runs on 127.0.0.1 if you are trying it on docker host machine, or on host machine IP if from outside of it. So docker don't need IP of host to start.
The other thing is if you are doing docker-composer up/start. Which means all services are in that docker compose file. In this case docker composer creates docker network for all containers in it. in this case you definitely can use fixed IPs for containers, though most often you don't need to because docker takes care of name resolution in that network.
if you are doing k8s way - then it is third way (production way), and it os another story.
if that is neither of above then please provide more info on how are you doing stuff.
EDIT - to:
if you are using docker composer and need to expose any of your containers to host machine you can do it through port mapping:
web:
image: some image here
ports:
- 8181:8080
left is the host machine port, right is container port
and then in browser on the host you can do request to localhost:8181
here is doc
https://docs.docker.com/compose/compose-file/#ports

Is there a way to make a request to a site hosted on local IIS from a docker container?

I've got a site running on my dev machine running in a docker container, and it needs to make a request to a site hosted locally on my machine, hosted via IIS. I've managed to get this working by specifying providing the extra_hosts in the docker-compose.override.yml file,
e.g.
extra_hosts:
- "dev-gb.company-qa.com:192.168.65.2"
- "dev-de.company-qa.com:192.168.65.2"
However the bridge IP I've specified is unique to my machine - the next dev that pulls it down will have to discover this IP and change it for themselves. Is there a cleaner, simpler way of accessing the site hosted on my machine without having to manually bind the host name to the bridged IP? I've read about host.docker.internal but I've no idea where that is supposed to go?

Recognize docker container from host machine browser

I have 2 dockers in a net: web and backend
When I access "web" from the host machine (http://web:3000) it works.
"web" have a "test connection" button to the backend machine, which just tries to access a static page on the backend machine (http://backend:80/isAlive)
But since the call is made from the browser, and the browser is on the host machine, then the "backend" hostname can not be resolved.
I can fix this by editing my host file to so that "backend" will be resolved to localhost, but is there a more intelligent way to do this?
You should strongly consider setting up a separate container acting as a reverse proxy forwarding requests to different containers using virtual hosts.
backend.foo.bar -> talks to backend container
web.foo.bar -> talks to web container
If you don't want do configure dns you can just map those names to localhost in your hosts file for now.
The quickest way to get this working is using jwilder/nginx. When you get it working you can go into the container and look at the generated config file for nginx and learn a fair bit in case you want to set this up manually in the future.
Again: This means that the jwilder/nginx container is the only one that maps a port to localhost. The other containers are proxied through it.

How to assign the host ip to a service that is running with docker compose

I have several services specified inside a docker compose file that are communication with each other via links. Now I want one of these services to talk to the outside world and fetch some data from another server in the host network. But the docker service uses its internally assigned IP address which leads to the firewall of the host network blocking his requests. How can I tell this docker service to use the IP address of the host instead?
EDIT:
I got a step further, what I'm looking for is the network_mode option with the value host. But the Problem is that network_mode: "host" cannot be mixed with links. So i guess i have to change the configuration of all the docker services to not use links. I will try how this works out.
You should open a port like to that service
ports:
8000:8000
The 8000 on the left is the host port and the 8000 on the right will be the IP port

How to create a service on the bridge network and the host network?

I've got a docker-compose.yml file with two services, web and auth.
Web will redirect to auth when authentication is necessary. Secondly, web talks to auth directly.
So it makes sense that my host machine is able to access both services and this works great since I can forward the ports, 3000 and 9000 for my host network.
However, the issue is that I cannot use the same localhost:9000 route when the apps talk directly to each other since that is on a separate bridge network.
Can I not have the auth service on both the host and bridge network? I've tried docker network connect container host and that explicitly fails. How do I get the two apps talking to each other while still being able to access them externally?
Each container has its own localhost which is not the same of the machine running them.
You could link the containers either specifying both the service name and a link alias (SERVICE:ALIAS), or just the service name. eg:
web:
...
links:
- auth
- auth:ldap
auth:
...
links:
- web
Containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.
Links also express dependency between services in the same way as depends_on, so they determine the order of service startup.
(cit. docker-compose docs)

Resources