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
- 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
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"]
vim index.html
<h1> Developer code </h1>
<h2>Modified the code data </h2>
<h3> 3rd time code-data modified </h3>
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>
Step 4: Execute the created shell script via cron srevice
To run the cron service
systemctl start cron.service
crontab -e
*/1 * * * * /<path of the shellscript>
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
we have successfully completed the task with the above steps
XXXXXXXXXXXXXX---------------------------XXXXXXXXXXXXXXXXXX
Top comments (0)