How to Create Web Server In Docker Container By Using Port Expose

Share via:

How to Create Web Server In Docker Container By Using Port Expose

In this article,we will see Create Web Server In Docker Container by using Port Expose.

Steps to Follow

  1. Create a Dominized Container “ktexperts-webserver” with image “ubuntu” and port mapping 80:80.
  2. Go inside the container “ktexperts-webserver”.
  3. Update Server Available Packages.
  4. Install webserver package “apache2”.
  5. Go inside “/var/www/html” directory and create a file “index.html”.
  6. Start apache2 service.
  7. Verify content of container “ktexperts-webserver”.

To see the list of all images

To see the list of all containers

1. Create a Dominized Container “ktexperts-webserver” with image “ubuntu” and port mapping 80:80

To see the list of running containers

2. Go inside the container “ktexperts-webserver”

3. Update Server Available Packages

4. Install webserver package “apache2”

5. Go inside “/var/www/html” directory and create a file “index.html”

6. Start apache2 service

Verify status of apache2 service

7. Verify content of container “ktexperts-webserver” 

Generally container won’t have any IP that’s why we expose the ports in both sides then give Docker Public IPV4 to users.

They can access container webserver through docker.

Copy Public IPV4 of the Docker

Search IPV4 Public IP along with default port and file in browser

We can see default port “80” and default file “index.html”

13.232.52.198:80/index.html is default port (80) and file(index.html).

Search IPV4 Public IP of Docker in browser

The default port “80” and default file “index.html” so,we no need to give the path directly we can give IPV4 Public IP of Docker.

Key Points

Demonized Mode (Even Though you exit from container,those will be running).
Container is running without going inside the container.
Map 2 ports while running the docker run command.
one port for base machine (Docker) and another one for container (ktexperts-webserver).
We can change host port but can’t container port.
Port 80 is the default port.
Container don’t have any IP Address but it has port.
We access the container web content through base machine IP Address.

Thank you for giving your valuable time to read the above information.

 

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

 

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Add Comment