I am using Docker for Mac. I am running a nodejs based microservice in a Docker container. I want to test node microservice through the browser. How to get IP address of running docker container?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
If you don't want to map ports from your host to the container you can access directly to the docker range ip for the container. This range is by default only accessed from your host. You can check your container network data doing:
Probably is better to filter:
Usually, the default docker ip range is
172.17.0.0/16
. Your host should be172.17.0.1
and your first container should be172.17.0.2
if everything is normal and you didn't specify any special network options.EDIT Another more elegant way using docker features instead of "bash tricking":
For my case, below worked on Mac:
I could not access container IPs directly on Mac. I need to use
localhost
with port forwarding, e.g. if the port is 8000, thenhttp://localhost:8000
See https://docs.docker.com/docker-for-mac/networking/#known-limitations-use-cases-and-workarounds
The original answer was from: https://github.com/docker/for-mac/issues/2670#issuecomment-371249949
You can start your container with the flag
-P
. This "assigns" a random port to the exposed port of your image.With
docker port <container id>
you can see the randomly choosen port. Access is then possible vialocalhost:port
.Use
--format
option to get only the IP address instead whole container info:if you want to obtain it right within the container, you can try
For modern docker engines use this command :
and for older engines use :