Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate instruction: Accessing a service of a container by container IP from the host #2277

Open
candleindark opened this issue Feb 5, 2023 · 2 comments

Comments

@candleindark
Copy link

You can access it by visiting `http://container-ip:15672` in a browser or, if you need access outside the host, on port 8080:

The above instruction doesn't seem to be correct. By default, I don't seem to be able to access a service provided by a container through the container's IP address from the host. This post confirms my experience as well.

@yosifkit
Copy link
Member

yosifkit commented Feb 6, 2023

I am unable to reproduce a problem on a regular Linux system using the bridge network; it works without using --publish/-p. The -p is required to enable access from outside the Docker host. For example, running Linux containers using Docker Desktop, then it is required to access it from the host (like Windows or OSX) since Docker is inside a VM.

$ docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management
Unable to find image 'rabbitmq:3-management' locally
3-management: Pulling from library/rabbitmq
7608715873ec: Pull complete 
5063b4e8e152: Pull complete 
89b7cb89a912: Pull complete 
27c7cee8f48c: Pull complete 
7204ec11924c: Pull complete 
33794a61c918: Pull complete 
c99fd6551816: Pull complete 
e8a147f91d59: Pull complete 
0c314e21ffac: Pull complete 
1d8181beff16: Pull complete 
e30eae262367: Pull complete 
Digest: sha256:ee66395719d01e6122ab4868dda83cc54e787a02118c6bcadc86aea0203b5669
Status: Downloaded newer image for rabbitmq:3-management
49005e12e1be8541b08f70167d4b3b904c27f005a4c24de08626a6c4cef62bb1
 $ docker ps
CONTAINER ID   IMAGE                       COMMAND                  CREATED         STATUS         PORTS                                                                                        NAMES
49005e12e1be   rabbitmq:3-management       "docker-entrypoint.s…"   3 seconds ago   Up 2 seconds   4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 15691-15692/tcp, 25672/tcp                         some-rabbit
$ docker container inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress }}' some-rabbit
172.17.0.4
$ ping 172.17.0.4
PING 172.17.0.4 (172.17.0.4) 56(84) bytes of data.
64 bytes from 172.17.0.4: icmp_seq=1 ttl=64 time=0.134 ms
64 bytes from 172.17.0.4: icmp_seq=2 ttl=64 time=0.079 ms
^C
--- 172.17.0.4 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.079/0.106/0.134/0.027 ms
$ curl http://172.17.0.4:15672
...
    <title>RabbitMQ Management</title>
...

@candleindark
Copy link
Author

I guess that explains it. I am using Docker Desktop on MacOS. However, it may still be useful to put some clarification about the assumption of using docker on Linux, etc. It would be especially useful to new comers to docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants