Docker - 5

 Docker Port Expose

====================


Container does not have its own ip adddress. it use host's ip address to communicate with outer world. we use port to connect the specfic container. We mapped host port with container port so we can communicate the container which we have connected recently. host port can be rename but container port can not be rename like port 80 can not be 81 in container.


-> login into AWS account create one linux instance

Now go to putty -> login to your account.


-> sudo su 

-> yum update -y

-> yum install docker -y

-> docker run -td --name techserver -p 80:80 ubuntu  (d - daemon means start the container but do not let me enter it)

-> docker ps

-> docker port techserver

0/p -> 80/tcp --> 0.0.0.0/80


-> docker exec -it techserver /bin/bash (exec mean it will let you enter in the container but it will fresh start the process.)

-> apt-get update

-> apt-get install apache2

-> cd /var/www/html

-> echo "Subscribe Tech Guftgu" > index.html

-> service apache2 start

http://10.28.195.13/


-> docker run -td --name myjenkins -p 8080:8080 jenkins/jenkins

http://10.28.195.13:8080/

Difference between docker attach and docker exec?


1) Docker exec creates a new process in the container's enviroment while docker attach just connect the standerd input/output of the main process inside container to corresponding standard input/output error of current terminal.


2)docker exec is specifically for running new things in a already started container, be it a shell or some other process.

docker exec creates pid -process id and ppid - parent process id.

---------------------------------------------

What is the difference between expose and publish a docker?


Basically you have three options:-

1) Neither specify expose nor -p

2) only specify expose

3) specify expose and -p


1. if you specify neither expose nor -p, the service in the container will only be accessible from inside the container itself.


2) If you expose a port, the service in the container is not accessible from Outside docker, but from inside other docker containers, so this is good for inter-container communication.


3) If you expose and -p a port, the service in the container is accessible from anywhere, even outside docker.


If you do -p but do not expose docker does an implient expose. This is because, if a port is open to the public, it is automatically also open to the other docker containers. Hence '-p' includes expose.



IMP note - once you stop the container then it will unmap the port from container.

Comments

Popular posts from this blog

GIT - 3

Docker - 6

GIT - 1