Table of contents
Port mapping is used to access the services running inside a Docker container. We open a host port to give us access to a corresponding open port inside the Docker container. Then all the requests that are made to the host port can be redirected into the Docker container.
EXPOSE 80
This tells Docker your webserver will listen on port 80 for TCP connections since TCP is the default. For UDP, specify the protocol after the port.
For more than one port, you can list EXPOSE more than once.
EXPOSE 80/tcp EXPOSE 80/udp EXPOSE 443/tcp EXPOSE 8081/udp
Steps For Docker Container Port Mapping
Launch an instance Ec2 -Ubuntu
Select Security Group Rule "HTTP port 80"
Launch an instance Ec2 -Ubuntu
Now open through Putty with the help of Ec2 -Keys
Now Update the Local System "UBUNTU"
apt-get update
Now Install Docker in Local System "UBUNTU"
apt-get install docker.io -y
Now Check Docker Version
docker --version
Now Search Image from Docker-Hub that image use to create Container
docker search <image_name>
Now Pull Image from Docker-Hub that image use to create Container
docker pull <image_name>
Now Create Container from Image
docker run -td --name container_01 -p 80:80 ubuntu
Now Check Container
docker ps -a
Now Check Port Mapped or Not
docker port <container_name>
Now Go inside the Container and update it
docker exec-it <container_name> /bin/bash
apt-get update
Now Install Apache Server inside the Container
apt-get install apache2 -y
Now Go inside the path
ls
cd /var/www/html
echo "content want to print on screen" >index.html
Now Restart the Apache Server
service apache restart
Now copy Public Ip Id From AWS account and Hit at Google
Now We can see the Container Port mapped and content showed
*****************************Thank You*****************************************