Connect with us

Hi, what are you looking for?

Hosting

Explained Docker Container Ports-Linux Juggernaut

Explained Docker Container Ports-Linux Juggernaut

Introduction

In previous articles we have talked about images of dockers, the origin and functioning of dockers and the dockers’ hub. In this document we will talk about the port network and in particular the transit of ports. Understanding how port forwarding works in the Container is very useful for anchoring web applications based on Apache or nginx. Before we start, we want to check which containers and images we have in the system.

[[email protected] ~]$ container docker ls
Container ID PICTURE STATUS LIABILITY NAMES ORDERED
[[email protected] ~]$ container ls -Name
[[email protected] ~]$ Image de ls
Repository Docker Container Change
SIZE
sahilsuri008/linuxnix-docker v1 e1c1d07a11b5 22 hours ago 182MB
ubuntu 16.04 13c9f1285025 3 weeks ago 119MB
[[email protected] ~]$.

From the above results we can conclude that two images and zero containers are running or stopped in this system. For this demonstration we do not use the Ubuntu image or the image we created. Instead, we run an image for nginx and show how port forwarding works. So let’s download the nginx image.

[[email protected] ~]$ docker running -d nginx
The image ‘nginx:latest’ cannot be found locally
: Library extract/Tilt
fc7181108d40 : Complete train
d2e987ca2267 : Pull out
0b760b431b11 : Fully digested: sha256:4 770a77003d3114c332bcab42d4fb18a8cd28cd4534162a2af648264 76cStatus : A newer image for nginx has been uploaded:last
09994d200778d9b781e7240bddf9b797f9007ee18e251a1cb5c770cd6f5c85a8
[[email protected] ~]$
[[email protected] ~]$ docker-container ls
Container ID COMMAND IMAGE STATUS PORT NAMES
09994d200778 nginx nginx -g ‘daemon…. 8 seconds ago Up to 6 seconds ago 80/tcp stupid_babbage
[[email protected] ~]$

The -d flag indicates that we want the container to run offline, i.e. we don’t want to connect to it after it has been booted up. If we wanted to connect to it, we would use the -it flags, which we have also used in previous posts. If you look at the exit of the docker ls, you will see that we have tcp port 80 open in the container. If you look at the documentation of the Docker ports, you will most likely come across two terms that are revealed and published. A port, if it is open, means that the port in the container is open and that we can connect to the container in that port on the local host. Because the published port implies that the host port is connected to the container port to allow access to the container from outside the local host. To find out which port in the image is open when the container is started, use the Docker Image History command followed by the name of the image.

[[email protected] ~]$ cartoon of nginx
IMAGE CREATED FROM SIZE HOW
f68d6e55e065 8 days ago /bin/sh -c #(nop) CMD [nginx -g daemon… 0B
8 days ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B
8 days ago /bin/sh -c #(nop) EXPOSE 80 0B
8 days ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx . 0B
8 days ago /bin/sh -c set -x && addgroup –system -… 54,1MB
8 days ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~stretch 0B
8 days ago /bin/sh -c #(nop) ENV NJS_VERSION=0,3.3 0B
8 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.17.1 0B
4 weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
4 weeks ago /bin/sh -c #(nop) CMD [bash] 0B
4 weeks ago /bin/sh -c #(nop) ADD file:5ffb798d64089418e… 55.3MB
[[email protected] ~]$.

Opening port 80 on the container means we can connect to it via eLinks or a similar utility on the local host, but not via a web browser. To display the IP address assigned to the Container, start Docker Inspect, followed by the name of the Container.

[[email protected] ~]$ docker inspects stupid_babbage | grep -i Ipadd
Secondary IP addresses: zero,
IP address: 172.17.0.2, API address: 172.17.0.2, [[email protected] ~]$.

From the above output we can set the IP address of the container to 172.17.0.2. To verify that nginx is running on port 80, delete the IP address.

[[email protected] ~]$ curl http://172.17.0.2.

Width: 35 m; box
: 0 car; font family
: Tahoma, Verdana, Arial, San Serif;
}

 

Welcome to nginx!

If you see this page, the nginx web server has been successfully installed and is running version
. Additional configuration is required.

Documentation and online support is available at
nginx.org.
Sales support is available at
nginx.com

Thanks for using nginx.

$ [[email protected] ~] $ [[email protected] ~]

The above conclusion confirms that Nnnix operates in the container at Port 80. If you now try to execute the same command by entering the local host instead of the Container’s IP address, you will get an error message. This is because port 80 of the Container is not connected to any of the ports on the local host for the connection. Now we start another container and connect local port 80 to container 80 using the -p option with the docker start command.

$ Docker running -d -p 80:80 nginxb4e38abf3ad6ea2ca563cd43b81c3896409b1f7d54c46ea4c8383d76c96a8 [[email protected] ~]$ docker container lsCONTAINER ID COMMANDO IMAGE CREATUS PORTS NAMESb4e38abff3ad6 nginx nginx -Demon…. 12 seconds ago. 10 seconds 0.0.0.0.0.0.0.0:80->80/tcp goofy_merkle09994d200778 nginx nginx -g ‘daemon… 22 minutes ago 22 minutes ago 80/tcp silly_babbage[[email protected] ~]$

We now see at the exit of the command docker’s container that our local port 80 is connected to the port 80 of the container. If we’re trying to use the curl command now, it should work.

[[email protected] ~]$ curl http://0.0.0.0

Width: 35 m; box
: 0 car; font family
: Tahoma, Verdana, Arial, San Serif;
}

 

Welcome to nginx!

If you see this page, the nginx web server has been successfully installed and is running version
. Additional configuration is required.

Documentation and online support is available at
nginx.org.
Sales support is available at
nginx.com

Thanks for using nginx.

 

[[email protected] ~]$ curl http://localhost.

Width: 35 m; box
: 0 car; font family
: Tahoma, Verdana, Arial, San Serif;
}

 

Welcome to nginx!

If you see this page, the nginx web server has been successfully installed and is running version
. Additional configuration is required.

Documentation and online support is available at
nginx.org.
Sales support is available at
nginx.com

Thanks for using nginx.

$ [[email protected] ~] $ [[email protected] ~]

Conclusion

This completes our introduction to port shipping in port containers. We hope you found this article useful and encourage you to experiment with port transport in the containers you use.

Explained Docker Container Ports-Linux Juggernaut

Debriefings:
8,788

The next two tabs change the content.

Explained Docker Container Ports-Linux Juggernaut

He started his career in IT in 2011 as a system administrator. Since then he has worked with HP-UX, Solaris and Linux operating systems and with high availability and virtualization solutions.
He is very interested in shell scripting, Python and Perl, he studies AWS cloud strings, DevOps tools and methods. He likes to share the knowledge he has acquired over the years with the rest of the community.

Explained Docker Container Ports-Linux Juggernautdocker ports explained

You May Also Like

Latest

Linux desktops are good in many ways, but like Windows they are not known as the most efficient battery. This does not mean that...

Latest

The United States Supreme Court has indicated that it will finally solve a problem that has been causing legal problems for almost two decades:...

Hosting

To secure your AWS assets, follow these AWS Identity and Access Management (IAM) guidelines. Locking the Root User Access Key for AWSAccount You use...

Hosting

A few days ago we discussed the installation of the Ubuntu 20.04 LTS office. Today we will show you with screenshots how to install...