Saturday, April 18, 2020

Docker Assignments #7: Docker, Nginx and index.html


  1. Create a folder name it as "docker-nginx"
  2. Create a file with name “index.html”  under “docker-nginx” folder
  3. Add <p></p> tag with sample text in index.html file
  4. Pull nginx:alpine docker image into host machine
  5. Write docker run command by setting following options
  • enable detached mode
  • set container name as "helloworldnginx"
  • set container working directory i.e. /usr/share/nginx/html
  • do bind mount of “docker-nginx” folder from host machine to container /usr/share/nginx/html folder 
  • map host port number to 8200
       6. Go to http://localhost:8200 from host machine to verify index.html 
       
 Command:
> docker run -d -p 8200:80
   --name helloworldnginx 
   --mount type=bind,source=/c/Users/rama/docker-nginx,target=/usr/share/nginx/html
   nginx:alpine  (or)

 > docker run  -d  -p 8200:80
   --name helloworldnginx 
   --mount type=bind,source=$(pwd),target=/usr/share/nginx/html 
   nginx:alpine  

(i.e. pwd should be docker-nginx folder)

  • -d  --> used to run container in detached/background mode
  • -p 8200:80  --> map host port number 8200 to container port 80 ( i.e. nginx expose port 80 by default )
  • /usr/share/nginx/html --> nginx default site enabled folder
Note : https://github.com/nginxinc/NGINX-Demos is a official nginx git repo and has awesome demos 

Happy Coding :) 




No comments:

Post a Comment