what should be used instead of 'host.docker.internal' when using nerdctl in place of docker? - docker

When using docker desktop, we would connect to the host machine from the container using the URL 'host.docker.internal'.
however container is not able to connect to the host machine (i.e my machine) when I am using nerdctl instead of docker.
I installed Rancher desktop to use nerdctl

ipconfig getifaddr en0
The above command will give the IP address of your wireless connection. Note, this will only work for MacOS. This IP can then be written to the /etc/hosts of your container against host.docker.internal as they share the same network. This can help the container communicate to the host machine by using host.dock.internal . Although, an elegant solution is expected from RancherDesktop (or its already available in the newer versions).

From lima docs.
The loopback addresses of the host is 192.168.5.2 and is accessible
from the guest as host.lima.internal.
So instead of host.docker.internal, provide 192.168.5.2
I have tested this with nerdctl distributed via Rancher and it works!
reference: https://github.com/lima-vm/lima/blob/master/docs/network.md

Related

Is it possible to access docker containers from the host machine by it's IP through bridge network

I'm using docker desktop for windows and I could ping to a container from the host machine by it's IP on Docker version 1.x.
Now it doesn't work anymore on Docker version 20.x.
I guess somewhat change for network isolation policy but not sure.
Is there any solution to access my containers by it's IP address again?

How to access docker container from mac machine using ip addr or a domain name

I am using Docker desktop, I have a couple of docker containers running using docker-compose and port forwarding. I can access the containers from my mac using localhost. On the second container, I am exposing on different ports. I can see ip addresses are associated to both containers by using docker inspect, but I cannot access using the ip address.
I would like access the container from my local mac by
dns domain
ip address
Any help appreciated.
Thanks
You cannot directly connect to the container-private IP addresses on MacOS. You also can't connect to them using a VM-based Docker implementation like Docker Toolbox or Kubernetes' minikube, or from a different host. Looking up and using these IP addresses, or trying to manually set them, usually isn't a best practice.
Instead you can use the docker run -p option to publish a port from your container to the host. Programs running directly on the host can access the container using localhost as a host name and the published port number. This works on all platforms; on VM-based solutions use the VM's IP address instead of localhost; from a different host, use the Docker host's DNS name or IP address.

Access devices on local network when running Docker for Mac

I have some smart wifi devices on my network I can see from a script on my Mac. But running the same script from within a Docker container those devices are not visible.
I assume this is related to Docker for Mac's inability to connect to the host's network using --network host or network_mode: host. I also assume this issue wouldn't exist on a Linux machine but I don't have one to test on.
What is the workaround?
Edit:
Confirmed this worked fine when running inside an Ubuntu virtualbox, but I'd really not have to develop inside it.
If you start the container with network option as host, the container will share the network stack of the host. Thus any device reachable from you host should be reachable by the container.
docker run --network host ...
Adding containers to a network would allow them to communicate with each other but if you want to access other services running on host then host.docker.internal (from 18.03+). I had to do the same in a mac mini setup to access external service.
[https://docs.docker.com/docker-for-mac/networking/]
If you have to access a service on another host then you can setup an nginx server on the docker host and a proxy pass rule to direct it to the remote service.

How do I give an own ip address to docker for Windows container?

I want to export the complete ip connectivity (UDP and TCP) from a docker container with a Linux app (ie give it's own ip address (in the same subnet as the host), that can be accessed from the host and from other physical machines on the network).
What do I need to configure in Windows, what in docker, what inside the container?
(NB: I don NOT want to expose ports as part of the host).
I finally solved the problem (for me) by installing Ubuntu in Virtual Box and using the docker containers from there. Not the most elegant solution but working on first try.

How to get mac host IP address from a docker container?

I want to access host IP address from a docker container on mac. I know how to do that on Linux by using the bridge0 interface. But docker for mac doesn't have bridge0. I tried to use the gateway 172.17.0.1 in a docker container but it doesn't work.
My docker for mac version is Docker version 1.13.0, build 49bf474.
I looked at this link https://github.com/docker/docker/issues/22753 but it mentions to create an alias on lo0 interface which I don't want to. Because our project is running inside docker container and I want to provides a general way without changing anything on the host.
Does anyone know how to do that in Mac?
From the Docker documentation :
I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The Mac has a changing IP address (or none if you have no network
access). From 17.06 onwards our recommendation is to connect to the
special Mac-only DNS name docker.for.mac.localhost which will resolve
to the internal IP address used by the host.
I think you'll need to upgrade your Docker For Mac version for this to work.
Updated Answer
it appears this answer has been deprecated and that you should now use host.docker.internal per docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-18030-ce-mac59-2018-03-26

Resources