Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker IPAddress Empty: Cannot Access Container

Tags:

java

docker

I built my container as follows:

docker build -t microservicedemo/corenlp .

Next, I ran it:

docker run -P -d --name corenlp microservicedemo/corenlp

And docker ps -a shows:

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                     NAMES
9e7d92c27e39        microservicedemo/corenlp   "java -Djava.secur..."   4 seconds ago       Up 2 seconds        0.0.0.0:32768->8080/tcp   corenlp

But I cannot access it at http://localhost:8080 or http://192.168.0.26:8080. When I run docker inspect 9e7d92c27e39 | grep IPA, the IP Addresses are NULL or "". Lastly, DOCKER_HOST is set as unix:///var/run/docker.sock.

I can't figure out how to access the container in a browser or via curl.

like image 234
acs254 Avatar asked Sep 18 '25 19:09

acs254


1 Answers

Look at the output of docker ps:

PORTS
0.0.0.0:32768->8080/tcp

This shows that container's port 8080 was published to host's port No 32768. This is where you should be connecting. You need to send requests to http://<your docker host ip>:32768 not http://<your docker host ip>:8080.

Beware that the -P option of docker run makes Docker map the all published container ports to random ports on the host, so next time you run the container 8080 might not be mapped to 32768 anymore! You can map the port explicitly if you want to avoid that:

docker run -p 8888:8080 -d --name corenlp microservicedemo/corenlp

This command will map container's port 8080 to the 8888 port on the Docker host machine (-p <host port>:<container port>).

EDIT

Docker host IP is the IP of the machine Docker daemon is running on (the service that hosts images, containers, volumes etc). In case of Linux it's the machine you installed Docker on (by default). In case of Windows and OSX it's the IP of docker-machine. DOCKER_HOST variable is in no way connected to the IP that Docker publishes the port to. It just defines how the Docker CLI (docker command) should connect to the above mentioned Docker daemon (dockerd).

like image 111
jannis Avatar answered Sep 21 '25 10:09

jannis