Noodles
Noodles

Reputation: 928

How can I access a docker container via ip address

I'm trying to replace our vagrant development setup with docker. I'd like to be able to use an ip like 10.10.10.10 for my docker container and allow developers to access their container via that IP. I'm currently using docker on Mac OS, but some developers use Windows.

How can I make this work?

Upvotes: 3

Views: 7233

Answers (2)

Admin
Admin

Reputation: 17

docker inspect

foundip address

Then u can connect it by ip address

Upvotes: -1

Roman
Roman

Reputation: 20256

If I'm reading the docs for Docker for Mac correctly, that's not possible

Per-container IP addressing is not possible

The docker (Linux) bridge network is not reachable from the macOS host.

and

I want to connect to a container from the Mac

Port forwarding works for localhost; --publish, -p, or -P all work. Ports exposed from Linux are forwarded to the Mac.

Our current recommendation is to publish a port, or to connect from another container. Note that this is what you have to do even on Linux if the container is on an overlay network, not a bridge network, as these are not routed.

There is also a pretty interesting discussion here about why there is no docker0 bridge to access containers directly. This comment suggests a workaround that might be good enough for your needs.

Upvotes: 8

Related Questions