HostOnNet Blog

Docker

Installing Docker

Working with Docker

Docker Tricks

Find IP of a running container

docker inspect --format '{{ .NetworkSettings.IPAddress }}' CONTAINER_NAME

To make a port in container available to host machine, use -P or -p, example

docker run --name hontest -d -p 80:8080 hostonnet/nginx

Here Port 8080 inside the container will be mapped to port 80 on host machine.

root@honVm:~# netstat -antp | grep LIST
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1825/sshd       
tcp6       0      0 :::22                   :::*                    LISTEN      1825/sshd       
tcp6       0      0 :::80                   :::*                    LISTEN      39376/docker-proxy
root@honVm:~# 

If you use -P option, all ports inside container will be published in host, but ports will be random.


Posted in Virtualization. Bookmark the permalink.