I have problems creating a container with a custom host IP (other than “localhost” or “127.0.0.1”; e.g. “192.168.59.123”) on MAC. If using “localhost”, all works well.
My goal is to make the database accessible for third party programs. Because containers of multiple projects might be active at the same time (true at the moment using another solution as Docker), the IP must be set to a custom IP.
I invested a whole day trying and searching in the Internet, but I could find only old threads about a bug in 2020. The solution there was to downgroad Docker Desktop. I had an old version from 1Q2024 and updated to the most recent version - I even un- and re-installed Docker Desktop -, but the problem still prevails.
Is there any additional configuration I have to set?
You are aware that Docker Desktop (Win/Mac) runs the containers in a Linux VM? So you not only need to configure the Docker container to expose ports, but must also tell Docker Desktop to expose the ports to the real host.
No, I was not aware of that. I thought, Docker containers are little Linux VMs, which run on the host machine. So that means, that Docker containers are little Linux VMs, which run inside a big Linux VM, which runs on the host machine? Thank you for telling me!
Can you tell me, how I expose the ports to the real host?
Containers are not full VMs, they still use the host’s kernel. You can think of them as isolated environments in a similar way to VMs, but it’s not the same and the distinction should be made.
When using Docker Desktop, they’re created within a Linux VM, yes.
I don’t know of any configurations that need to be made though, I use Docker Desktop on three Macs and the ports map just as well as when I am using Docker Engine on Linux
May I ask though, why you’re using the long syntax for the port mapping?
ports:
- 1234:1234
May this not work just as well?
Sorry, I have jumped in without reading the entire bit, what are you trying to do by specifying the IP?
I am using the long syntax, because it provides a better overview for people, who doesn’t work much with Docker. For the short syntax, you need to know which part means what. In the long syntax, each part has a proper name.
I tried the short syntax, but it didn’t work either.
I want to type in the IP and port in my host machine’s browser and get access to the database, which runs inside the Docker container.
Sorry perhaps not the best link, but anyway, MAC vLAN may be what you’re looking for - But it is only supported for Docker Engine on Linux, and will not work on a Mac
By following your link, then following other links, then continue following links (currently, I have 21 open tabs in my browser xD), then gathering all their information, then trying for 3 hours, I managed to succeed!
My configuration is exactly like in my original post above. All what was missing was to create a new network interface on my host machine and give it the IP address. The port forwarding of the container worked, immediately.
Have a nice day!
P.S.:
I also activated the beta feature for host networking. This alone didn’t work, but might have helped.