Author: Sahil Suri

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

Docker Volumes explained

Introduction In earlier posts, we created a script in our container and we were able to execute it. But when the container is removed the script will get removed right along with it. What if we wanted the files created during our container lifecycle to persist after the container has been terminated? We could do so by using docker volumes which are the preferred mechanism for allowing data persistence in Docker containers. Advantages of docker volumes: They can be used on both Linux and Windows containers. We can use volume drivers to store data on a remote host or even a cloud provider. New volumes can have their content pre-populated by a container.   We’ll now walk you through a step by step process to create a docker volume and mount it in a container. Step 1: Create a docker volume. Before we create our volume let’s check the system for any existing volumes. [sahil@linuxnix ~]$ docker volume ls DRIVER VOLUME NAME [sahil@linuxnix ~]$ We’ll now create out docker volume using the docker volume create command. [sahil@linuxnix ~]$ docker volume create linuxnixvol linuxnixvol Let’s run docker volume ls again to verify that our volume has been created. [sahil@linuxnix ~]$ docker volume ls DRIVER VOLUME NAME local linuxnixvol [sahil@linuxnix ~]$ Step 2: Retrieve info about the volume [sahil@linuxnix ~]$ docker volume inspect linuxnixvol [ { "CreatedAt": "2019-07-10T08:10:00Z", "Driver": "local", "Labels":...

Read More

Docker networking commands explained

Introduction Our last article was a theoretical introduction to the Docker networking stack comprising the container network model and its components. In this article, we’ll be demonstrating some useful docker networking related commands including how to create and inspect networks in Docker. Before getting started with the docker networking commands let’s run ifconfig command on our docker host to see the adapters. [sahil@linuxnix ~]$ ifconfig -a docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:c1:a9:d8:99 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001 inet 172.21.17.134 netmask 255.255.240.0 broadcast 172.21.21.255 inet6 2406:da18:77c:6102:6682:ca26:b37:c059 prefixlen 128 scopeid 0x0<global> inet6 fe80::471:43ff:fec0:81a4 prefixlen 64 scopeid 0x20<link> ether 06:71:43:c0:81:a4 txqueuelen 1000 (Ethernet) RX packets 2185 bytes 814542 (795.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2880 bytes 596702 (582.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 16 bytes 1036 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1036 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0...

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

Email Subscribe

ABOUT ME..!

My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.