In the month of March 2020 I had training on docker technology where I learnt lots of things under the guidance of Mr. Vimal Daga sir , now we are concluding this training so I have made this project for implementing whatever we have learnt in the 24 hours online class.
This is a project along with my experience while learning docker whatever problems I faced how I resolved them is provided here.
We will require an operating system it may be bare metal or virtual machine I have used RHEL version 8 for the same. Basically I have windows installed on my machine on the top of it I have installed RHEL 8 as a virtual machine.
- First of all copy the path of url from where we are going to install docker
https://download.docker.com/linux/centos/7/x86_64/stable/I would suggest go through this URL for installation. In the RHEL I have configure yum for installing community eddition of Docker. - I faced one problem where my docker container was unable to run as security system was refusing so I have got the solution while qna
setenforce 0this will turn of security enforcement.
- This is very simple task we just have to pull images of os from
https://hub.docker.com/I have used centos image for configuring my webserver as well as a client . https://hub.docker.com/_/centosthis is the official image provided by centos we can pull this image bydocker pull centosthis command
- I have created my own network for this project for convinience in development.
docker network create --driver bridge webnethere driver is network mode I have used bridge as I have to communicate with internet.
- I have launched one centos image in my container using
docker run -it centos:latestcommand. - for configuration of webserver I have installed some softwares. First of all I was going to deploy my website on apache webserver so I have downloaded required softwares.
- for installing apache webserver there are 3 steps
- Software installation using
yum install httpd - Deploying webpages inside
/var/www/htmlfolder - Start services using
systemctl start httpd.servicesbut in docker container systemctl process doesn't initializes so we have usingyum install httpdI have installed software for webserver.
- Software installation using
- Now I have to deploy my website on apache webserver as I have mentioned earlier we have keep all the data that we have in
/var/www/htmlfolder - I have keep my webpages and other data in my github repository
https://github.com/ajinkya48765/Docker-Project---Develpement-Repo - For github intrigation I have installed git in my image using
yum install git. - I have fetched all the data from my repo and kept inside that folder.
- Now we are all set with website deployment now we just have to start service.
- In centos at the time of os booting one file always runs and that is
/etc/bashrcso we will keep our command for server creation in it so that everytime when os boots this command will run. - while doing this I faced a problem because when os boots it creates process of server creation but and information is stored in
/var/run/httpd/folder so we also have to remove this complete folder before running booting container. I have usedrm -rf /var/run/httpd/*command for this. - Now my webserver is completely automatic now I just want a volume which will store all of my data.
- Volumes are the preferred mechanism for persisting data generated by and used by Docker containers
- Volumes are easier to back up or migrate than bind mounts.
- You can manage volumes using Docker CLI commands or the Docker API.
- Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.
- Volumes work on both Linux and Windows containers.
- Volumes can be more safely shared among multiple containers.
- Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.
- New volumes can have their content pre-populated by a container.
- So I have created a volume called webset for storing all my data using
docker volume create webset
- Now as I have configure normal centos according to my requirenment and I have to save it so we have an option called commit.
docker container commit [OPTIONS] container [REPOSITORY : VERSION]
- now as we have created our own image now we can multiply this as many times we want and can make as many servers we want in just few seconds.
- But this time while creating an image I have mount my volume in the storage folder I used
dockerthis command. - as you can see along with volume I have also used network as my personel network which I have created earlier.
- Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.
- Start, stop, and rebuild services
- View the status of running services
- Stream the log output of running services
- Run a one-off command on a service
- We have to create file docker-compose.yml this name should always be same.
- Then we have some more options like in one click we can build whole infrastructure using
docker-compose upcommand. - To stop services temporary we have
docker-compose stop - To start stopped services we have
docker-compose start - To destroy whole infrastructure we have
docker-compose down