specify ip address for docker for mac - macos

I'm using Docker for Mac Beta and it runs from spotlight.
Is there any way to run it from console or force to use any configuration file to specify ip address for docker host.
Right now it changing from 192.168.64.3 to 192.168.64.5 (each start of docker it can have any random IP)
probably I need to configure bridge interface?
com.docker.network.bridge.enable_ip_masquerade: true
com.docker.network.bridge.host_binding_ipv4: 0.0.0.0
Does anyone know how to do that?

You can connect to the Docker alpine host via unix socket but I have not been able to figure out how to bridge to the network.
The docs say:
Unfortunately, due to limtations in OSX, we’re unable to route traffic
to containers, and from containers back to the host.
Because of the way networking is implemented in Docker for Mac, you
cannot see a docker0 interface in OSX. This interface is actually
within HyperKit.

Related

Equivalent of "host" network with docker-compose for containers running on windows

I'm using docker-compose on linux. In my compose-file I have network_mode: "host" for bunch of containers. This is convenient for my stack to able to access my containers as localhost:<port>.
Now I've had to run this on windows and it doesn't work. I've read this in the docs:
The host networking driver only works on Linux hosts, and is not
supported on Docker Desktop for Mac, Docker Desktop for Windows, or
Docker EE for Windows Server.
So.... anyways I have to access my container's exposed port on windows by some other means, as localhost:port as I on linux? Or do I HAVE to map them out to some random IP and access something like 3.70.0.1:port on windows?
To clarify this question and related issue. See comments on the question for details.
Indeed, simply specifying
ports: <host>:<container>
allows you to access your container/services as localhost:<host> from the host on linux/windows (likely mac too). That being said, specifying network_mode: host in your docker-compose.yaml service definition actually disables this on windows (and likely mac) systems.
A related issue I was having was that in some of my service, the IP address for communication between containers was of the type localhost:<container>. If you use network_mode: host, then indeed from both the host and container's perspective, the service run on localhost. However if you just use port mapping, then while the service run on localhost from the host's perspective, they then run on docker's private network from the service's perspective. So they will expect an IP address of the form <service_name>:<container_port> to communicate between containers.

Docker Networking: Linux Container on Windows Host

I have a Home Assistant Docker container.
It works fine so far.
Now I try to get my Video Surveillance into Home Assistant.
I have set up the RTSP Stream and so on.
So now to the Problem:
Every time I try to open the RTSP Stream from my Docker Container, it needs a random UDP high Port.
I only exposed the 8123 TCP from docker, but I also tried to expose more via port range and UDP, but I have other apps also running on my home Server, and they interfere.
Now the Question:
Is there a way to expose the whole Container to the Local Network with its own IP address?
I really won’t mess with the port problem inside my local network.
I know there is a solution out there with Hyper-V, but I really want to keep WSL 2.0 and not switch to legacy.

Bind custom IP to my Docker network's gateway to access containers from host

As far as I know, by default, Docker binds to 127.0.0.1 when running docker compose with the default network settings. To access my containers, I need to map alternate ports to access them through localhost, such as 45001:80 to access my web server container from the host.
I would like to bind my containers to an alternate IP then 127.0.0.1 on my machine so I can use the proper ports instead of having to forward the ports through localhost. For example, to access my web server container, instead of going to 127.0.0.1:45001, I would bind to something like 192.168.0.1 and access it via 192.168.0.1:80. I've tried searching for an answer for this, but I can't seem to find it. Going through the Docker documentation hasn't gotten me terribly far either.
Anybody know how I would accomplish this?

Can I run a docker container with an own, externally and host accessible, IP address on a Mac

I want to run an WebRTC gateway in a docker container on my Mac.
I need to export essentially all ports (TCP and UDP) (Specify -p does not help because there seems to be limit on the number of ports) with its own IP address. Using --net=host does not work on Mac.
Is there another option?
You can expose all ports using -P (note the uppercase) or --publish-all=true (is the same) on docker run command.
Link to docker docs about this.
Then you can check the mappings docker assigned using:
docker port yourContainerName
My previous answer is identical to a similar question (about doing essentially the same thing on a different platform (ie Windows)).
The problems encountered on both platforms are different (because Mac OX and Windows have a different network stack), but the workaround is the same.
I think the answer (would help someone) encountering the problem (on both cases).

Unable to access MongoDB within a container within a Docker Machine instance from Windows

I am running Windows 7 on my desktop at work and I am signed in to a regular user account on the VPN. To develop software, we are to normally open a Dev VM and work from in there however recently I've been assigned a task to research Docker and Mongo DB. I have very limited access to what I can install on the main machine.
Here lies my problem:
Is it possible for me to connect to a MongoDB instance inside a container inside the docker machine from Windows and make changes? I would ideally like to use a GUI tool such as Mongo Management Studio to make changes to a Mongo database within a container.
By inspecting the Mongo container, it has the ports listed as: 0.0.0.0:32768 -> 27017/tcp
and docker-machine ip (vm name) returns 192.168.99.111.
I have commented out the 127.0.0.1 binding host ip within the mongod.conf file also.
From what I have researched so far, most users resolve their problem by connecting to their docker-machine IP with the port they've set with -p or been given with -P. Unfortunately for me, trying to connect with 192.168.99.111:32768 does not work.
I am pretty stumped and quite new to this environment. I am able to get inside the container with bash and manipulate the database there however I'm wondering if I can do this within Windows.
Thank you if anyone can help.
After reading Smutje's advice to ping the VM IP and testing it out to no avail, I attempted to find a pingable IP which would hopefully move me closer to my goal.
By doing "ifconfig" within the Boot2Docker VM (but not inside the container), I was able to locate another IP listed under eth0. This IP looks something like 134.36.xxx.xxx to me and is pingable. With the Mongo container running I can now access the database from within Mongo Management Studio by connecting to 134.36.xxx.xxx:32768 and manipulate the data from there.
If you have the option of choosing the operating system for your dev VM, go with Ubuntu and setup docker with all of the the containers you want to test on that. Either way, you will need to have a VM for testing docker on windows since it uses VirtualBox if i'm not mistaken. Instead, setup an Ubuntu VM and do all of your testing on that.

Resources