Docker Port Forwarding | Start/Remove/Stop Containers – Part 4

In the previous blog we have seen how can we connect to the containers and we have seen how to connect to the nginx service from our host machine. Let’s now have a look into how to connect to the nginx service from our laptop using port forwarding.

Port Forwarding

Port forwarding, or tunneling, is the behind-the-scenes process of intercepting data traffic headed for a computer’s IP/port combination and redirecting it to a different IP and/or port.

Let say if i want to access the container using host IP/via my laptop browser, that would be great. Let’s do that using Port Forwarding. In port forwarding our request goes to the specified port of the host machine, which is then further navigated to the container’s concerned port.

docker run --name open-engine -d -p 8090:80 nginx

8090 port is of the host machine which will forward the request to port 80 of the container.

Let’s open this in a browser. Before that make sure to check the security groups as well.

Start/Stop/Delete container

docker start {name/id}
docker stop {name/id}
docker rm {name/id} 
docker rmi {image} => for image

/**please note that you cannot delete an image till container created from the image is exiting **/

Default directory of docker where all the data is stored is /var/lib/docker

Above are the container id. Let’s have a look at the container size w.r.t the images.

Image size is 132 MB whereas the size of the container is 40KB. This is because the container does not copy the image data. Do not treat container like a VM. Container is created in the Kernel space.

All the data which is shown in the container is from the image. If you feed some data in the container, then its size grows.

About the author

Deepak Sood

Deepak Sood is Lead Consultant in an IT firm holding expertise in Devops and QA Architecture with 8 years of experience.

His expertise is in building highly scalable frameworks. His skills include Java, Configuration Management, Containers, and Kubernetes.

Reach out to him using contact form.

View all posts