Docker container ports explained
Introduction In earlier articles we’ve talked about docker images, creating and running docker containers as well as the docker hub. In this post, we’ll talk about Docker networking and specifically port redirection. An understanding of how port redirection works in the container is very useful while dockerising web applications that rely on apache or nginx. Before getting started let’s check what containers and images we have available on our system. [sahil@linuxnix ~]$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [sahil@linuxnix ~]$ docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [sahil@linuxnix ~]$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE sahilsuri008/linuxnix-docker v1 e1c1d07a11b5 22 hours ago 182MB ubuntu 16.04 13c9f1285025 3 weeks ago 119MB [sahil@linuxnix ~]$ From the above output, we can determine that we have two images and zero containers running or in a stopped state on this system. For the purpose of this demonstration, we don’t be using the Ubuntu image or the image that we created. Instead, we’ll pull an image for nginx and run it to exemplify how port redirection would work. So, let’s download the nginx image. [sahil@linuxnix ~]$ docker run -d nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx fc7181108d40: Pull complete d2e987ca2267: Pull complete 0b760b431b11: Pull complete Digest: sha256:40d9770a77003d3114c332bcab42d4fb18a8cd28c4534162a2af6482641b876c Status: Downloaded newer image for nginx:latest 09994d200778d9b781e7240bddf9b797f9007ee18e251a1cb5c770cd6f5c85a8 [sahil@linuxnix ~]$ [sahil@linuxnix ~]$ docker...
Read More