Docker Port And Expose

Docker Port And Expose

Login into AWS account create one linux instance
Now go to putty -> login as -> ec2-user
- sudo su
- yum update -y
- yum install docker -y
- service docker status
- service docker start
- docker run -td --name techserver -p 80:80 ubuntu
- docker ps
- docker port techserver
op -> 80/TCP -> 0.0.0.0/80
- docker exec -it techserver /bin/bash
- apt-get update
- apt-get install apache2 -y
- cd /var/www/html
- echo "Subscribe TechGuftgu" >index.html
- service apache2 start
- docker run -td --name myjenkins -p 8080:8080 jenkins

Difference between docker attach and docker exec ?

Docker exec creates a new process in the container's environment while docker attach just connect the standard Input/ Output of the main process inside the container standard input/output error of current terminal.

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

What is the difference between expose and publish a docker?

Basically you have three options:-
* Neither specify expose nor -p.
* Only specify expose.
* specify expose and -p

a) If you specify neither expose nor -p, the service in the container will only be accessible from inside the container itself.
b) 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.
If you do -p but do not expose docker does an implicit 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.
c) If you expose and -p a port, the service in the container is accessible from anywhere, even outside docker.

Did you find this article valuable?

Support </Shishir-Learns> by becoming a sponsor. Any amount is appreciated!