Containerizing the website
Option 1: Manually creating a docker image
Steps:
- lets create a vm and setup docker
- Lets create a nginx container
docker run -d --name infinite_loop -P nginx
- Lets findout the folder where website can be copied
/usr/share/nginx/html
- commands to execute
cd /tmp/
mkdir infinite
cd infinite/
wget https://www.tooplate.com/zip-templates/2117_infinite_loop.zip
apt install unzip -y
sudo apt install unzip -y
unzip 2117_infinite_loop.zip
ls
cd 2117_infinite_loop/
ls
docker --help
docker cp --help
docker ps
docker cp . infinite_loop:/usr/share/nginx/html
docker exec infinite_loop ls /usr/share/nginx/html
docker exec infinite_loop ls -al /usr/share/nginx/html
docker --help
docker commit --help
docker commit infinite_loop infinite_web
docker image ls
docker run -d --name infinite_2 -P infinite_web:latest
docker ps
docker rm -f $(docker ps -a -q)
docker run -d --name web_1 -P infinite_web:latest
docker run -d --name web_2 -P infinite_web:latest
- The problem with above approach is for every change we need to do this manual steps.
Option 2: Dockerfile
- Dockerfile has set of instructions on the steps that needs to be executed to create a image
- Dockerfile
- create a new directory. and create a file called as
Dockerfile
- Ensure your website is present in same directory
- In Dockerfile we have many instructions
- Dockerfile
FROM nginx:1.29
COPY . /usr/share/nginx/html/
EXPOSE 80/tcp
- Now lets build a image based on this Dockerfile

- Now run the container with the image
docker run --name web1 -d -P infinite_image:v1.0
docker ps
- docker image can be tagged to have multiple aliases
docker image tag infinite_image:v1.0 shaikkhajaibrahim/infinite_image:v1.0

- I want to push this image to my dockerhub account: refer to prompt below
Give me instructions to push a image to docker hub right from signing up configuring credentials and pushing images

Now lets redo this for a different website
- Website zip Refer Here
- watch classroom recording
- observation: while pulling the images sometimes we are seeing
Already Exists

Exercise
- Repeate the image building with following base images
- httpd
- alpine (install nginx)
Like this:
Like Loading...