Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access container's web application from host

Tags:

docker

I am running a site inside Docker container which exports following https://172.17.0.2:8443/admin/ & http://172.17.0.2:8463/users/

$ docker run -it -d --expose=8000-9900 ubuntu-java8-webapp
bf193d011fd8....

Docker PS cmd

$ docker ps -a
CONTAINER ID   IMAGE       COMMAND      PORTS          NAMES
bf193d011fd8   ubuntu-.... "/bin/bash"  8000-9900/tcp  desperate_mclean

Docker ls cmd

$ docker-machine ls    
NAME      ACTIVE   DRIVER       STATE     URL          DOCKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.10.3

Docker machine ip cmd

$ docker-machine ip default
192.168.99.100

How do I access the site? Just in case it matters, I am running docker on Mac here.

like image 736
Vic Avatar asked Mar 22 '16 05:03

Vic


People also ask

How do I access the Docker web app?

Head over to http://localhost:8888 and your app should be live. Note If you are using Docker Machine, you may need to open up another terminal and determine the container ip address using docker-machine ip default .

How do I access the outside container?

Published ports To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.

What command can you use to view a container's logs?

The docker logs command shows information logged by a running container. The docker service logs command shows information logged by all containers participating in a service. The information that is logged and the format of the log depends almost entirely on the container's endpoint command.


1 Answers

You can try and access it through the docker machine IP:

https://192.168.99.100:8443/admin
http://192.168.99.100:8463/users

But ideally, you would:

  • map those port to the host:

    docker run -p 8443:8443 -p 8463:8463 ...
    
  • port-forward those port to your actual host through VirtualBox VM Network setting, and access the site with:

    https://localhost:8443/admin http://localhost:8463/users

like image 137
VonC Avatar answered Nov 15 '22 18:11

VonC