Sunday, February 27, 2022

Docker Volume Assignment

 1. Create a docker apache image using Dockerfile.

 2. Create a deploy-vol docker volume.

 3. Run a container using docker apacheimg with port forwarding 80:80 and map /var/www/html folder to deploy-vol.

4. Check default apache page is accessible on the browser.

5. Copy/Create a test.html file under /var/lib/docker/volumes/deploy-vol/_data

6. Check on the browser that you are able to access this webpage (test.html)

7. Go inside the container and create a file newtest.html under /var/www/html and verify that you are able to access it with the browser.

9 comments:

Muhd Irfan Abdul Rahman said...
This comment has been removed by the author.
Muhd Irfan Abdul Rahman said...

1. vi Dockerfile

1.2 in Dockerfile:
FROM ubuntu
#from is getting the base image

ARG DEBIAN_FRONTEND=noninteractive
#noninteractive for automation so it does not ask questions such as geographical..

RUN apt-get update
#run is adding instruction on the instruction layer

RUN apt-get -y install apache2

ADD . /var/www/html
#add is copy the file from host machine to docker image folder

ENTRYPOINT apachectl -D FOREGROUND
#entrypoint whenever docker image is used in a container, some commands need to be executed automatically

ENV name DEVOPS
#environment variable is used on the global level

1.3 docker build . -t apacheimg

2. docker volume create deploy-vol

3. docker container run --name assignment1 -v deploy-vol:/var/www/html -dit -p 80:80 apacheimg

4. curl localhost

5. echo "h1 Welcome to test.html page! /h1" > /var/lib/docker/volumes/deploy-vol/_data/test.html

6. curl localhost/test.html

7. docker exec -it assignment1 bash

7.2 in container:

echo "h1 This is newtest page and NOT test page! /h1" > /var/www/html/newtest.html

7.3 exit container:

exit

7.4 curl localhost/newtest.html

Raman said...

Excellent

Jerome said...

1. Create a docker apache image using Dockerfile.
-> vi Dockerfile
FROM ubuntu
ENTRYPOINT ["echo"]
CMD ["Hello World"]FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl -D FOREGROUND
ENV name DEVOPS

-> docker build . -t apacheimg

2. Create a deploy-vol docker volume.
->  docker volume create deploy-vol

3. Run a container using docker apacheimg with port forwarding 80:80 and map /var/www/html folder to deploy-vol.
-> docker container run -dit —name c1 -v deploy-vol:/var/www/html -p 80:80 apacheimg

4. Check default apache page is accessible on browser.
On browser enter: localhost:80 , > Apache2 Ubuntu Default Page running

5. Copy/Create a test.html file under /var/lib/docker/volumes/deploy-vol/_data
-> echo “test text ABC” > /var/lib/docker/volumes/deploy-vol/_data/test.html

6. Check on the browser that you are able to access this webpage (test.html)
-> On browser enter: localhost/test.html , yes

7. Go inside the container and create a file newtest.html under /var/www/html and verify that you are able to access it with the browser.
-> docker exec -it c1 bash
-> echo "Second test page" > /var/www/html/newtest.html
-> On browser enter: localhost/newtest.html , yes

Raman said...

Great Work

Chin YZ said...

1. mkdir dockasgn
cd dockasgn
vi Dockerfile
FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl -D FOREGROUND
ENV name DEVOPS

2. docker volume create deploy-vol

3. docker container run -dit --name apacheimg -v deploy-vol:/var/www/html -p 80:80 ubuntu

4. curl localhost:80

5. echo “Test HTML” >> /var/lib/docker/volumes/deploy-vol/_data/test.html

6. localhost/test.html

7. docker exec -it apacheimg bash
touch /var/www/html/newtest.html
exit
ls /var/lib/docker/volumes/demo-vol/_data

Raman said...

Great Work

Naveen said...

1. vi Dockerfile

FROM ubuntu

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN apt-get -y install apache2

ADD . /var/www/html

ENTRYPOINT apachectl -D FOREGROUND

ENV name DEVOPS

docker build . -t apacheimg

2. docker volume create deploy-vol

3. docker container run --name a1 -v deploy-vol:/var/www/html -dit -p 80:80 apacheimg

4. Checked ok

5. echo "h1> Hello World /h1>" > /var/lib/docker/volumes/deploy-vol/_data/test.html

6. checked ok

7. docker exec -it a1 bash
cd /var/www/html
echo "h1> Second test /h1>" >> newtest.html
checked ok

Unknown said...

Mikraj:

1. Create a docker apache image using Dockerfile.
vi Dockerfile
FROM ubuntu
#from is getting the base image
ARG DEBIAN_FRONTEND=noninteractive
#noninteractive for automation so it does not ask questions such as geographical..
RUN apt-get update
#run is adding instruction on the instruction layer
RUN apt-get -y install apache2
ADD . /var/www/html
#add is copy the file from host machine to docker image folder
ENTRYPOINT apachectl -D FOREGROUND
#entrypoint whenever docker image is used in a container, some commands need to be executed automatically
ENV name DEVOPS
#environment variable is used on the global level
docker build . -t apacheimg

2. Create a deploy-vol docker volume.
docker volume create deploy-vol

3. Run a container using docker apacheimg with port forwarding 80:80 and map /var/www/html folder to deploy-vol.
docker container run -it --name c1 -p 80:80 --mount source=deploy-vol,destination=/var/www/html -d apacheimg

4. Check default apache page is accessible on the browser.
curl localhost OR localhost:80 on browser

5. Copy/Create a test.html file under /var/lib/docker/volumes/deploy-vol/_data
vi test.html
h1 hello this is practice /h1
cp test.html /var/lib/docker/volumes/deploy-vol/_data

6. Check on the browser that you are able to access this webpage (test.html)
curl localhost/test.html OR localhost/test.html on browser

7. Go inside the container and create a file newtest.html under /var/www/html and verify that you are able to access it with the browser.
docker exec -it c1 bash
cd /var/www/html
touch newtest.html
echo “h1 this is added, this new test /h1” >> newtest.html
curl localhost/newtest.html OR localhost/newtest.html on browser

Post a Comment