DEV Community

Kannan
Kannan

Posted on

Project task #1

We have received some task to complete, lets look the questions.
1.create a github repo with README.md
2.create a Dockerfile
3.write a shellscript to do the below
3.1 clone the repo
3.2 docker build
3.3 push to dockerhub
3.4 run docker container

  1. execute the shell script to run once in 1 min via cron service 5 make some changes on the index.html file and verify the changes.

find the below procedure to complete the above requirements

step 1. create a new gitrepo

Image description

step 2. create a Dockerfile and define how to build the docker image

vim Dockerfile FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -y RUN apt-get install apache2 -y RUN apt-get install apache2-utils -y RUN apt-get clean COPY index.html /var/www/html/ EXPOSE 80 CMD ["apache2ctl","-D","FOREGROUND"] 
Enter fullscreen mode Exit fullscreen mode
vim index.html <h1> Developer code </h1> <h2>Modified the code data </h2> <h3> 3rd time code-data modified </h3> 
Enter fullscreen mode Exit fullscreen mode

step 3: write a shell script

#!/bin/bash #clone the github repo git clone https://github.com/<gitusername>/<repo name> #Navigate the repo dir cd testprojectrepo #Build the Docker image docker build -t <image name> . #Push the docker image docker push <git username>/<image name> #Run the Docker container on detached mode docker run -d --name <container name> -p <Port> <image name> 
Enter fullscreen mode Exit fullscreen mode

Step 4: Execute the created shell script via cron srevice
To run the cron service

systemctl start cron.service crontab -e 
Enter fullscreen mode Exit fullscreen mode
*/1 * * * * /<path of the shellscript> 
Enter fullscreen mode Exit fullscreen mode

made some changes on the index.html file and verify the browser

Push the build shell script to the git repo

git init git status git add <Shell script file> git commit -m "comments" git push origin main 
Enter fullscreen mode Exit fullscreen mode

we have successfully completed the task with the above steps
XXXXXXXXXXXXXX---------------------------XXXXXXXXXXXXXXXXXX

Top comments (0)