Skip to main content

What is docker & vagrant and how to use it

Why Need Docker : 
Lets suppose we are working in a large application which needs ,Drupal 8 ,PHP7.4, Mysql 8, Redis server, Mongodb,solar server, nodejs server etc. And at the same time I also give maintenace for another project on drupal 7, But it needs some old version of php, mysql,redis etc because it is old project developed 4 year before.
So it's too complicated to run both the project in same machine just because of dependencies,
Proublem 2 : Lets suppose in local we work on apache & sqlite & on production nginx & mysql, So may be some issue should be raised in production,

To handing this type of situation Docker & vergant is much helpfull.

How is Docker Different from Vagrant?:
Docker : Docker is often described as "lightweight," because it simply provides containers within the host machine's Linux operating system. Docker containers hold an application's components, including binaries, libraries, and configurations, as well as the application's dependencies.
Vagrant is a workflow for development projects. Vagrant provisions any machine, which is typically a virtual machine (but does not need to be).

Difference in Docker & vagrant : 

1 - Where Docker relies on the host operating system, Vagrant includes the operating system within itself as part of the package. 
2 - Docker containers run on Linux, but Vagrant files can contain any operating system. That said, Docker does work with non-Linux operating systems. It just needs to run within a Linux virtual machine.
3-  Docker provides VMs for Mac and 64 bit Windows, or you could use another. 

Difference between image & container  in respect of docker:
image is just a file having some information, while container is created by image, & container is build it utilize the some system resources like CPU,Memory,HDD etc,

Lets suppose we have a mango seed(it is an image) It has the ability to build a mango tree(container) if we plant it,

Some terms :
Docker client : In your machine docker install as client, When we request any image then first it search it in my machines if found that good, if not then it ask to docker server or deamon, it will download your image from the docker hub.

Docker Commands : 

docker run busybox : (it an image) When we run an image then it converts as a container,

docker run = docker create + docker start
docker create hello-world : It create only the conatainer
docker start -a {hash-key of container} , -a is to attach to container
docker logs {hash-key} - logs of a container
docker kill {container-id}
docker exec -i -t {container-id} - To open the shell comman line of the conatqainer where i : attch to stdin, where t : to show the data as formated
docker ps : It shows currently running conatiner at this time in the machine
docker ps --all : It shows all the container
docker stop {container-id} : to stop any container
docker container ls : to listout all the containers
docker network ls : 
docker volume ls :
docker volume rm {volume id} : to remove the volume, make sure you remove the container first


 Docker Compose : 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. Then, with a single command, you create and start all the services from your configuration.

Lets Suppose we use a drupal project, So we need many containers, like db,redis,php etc, So we can define all of them in single file docker-compose.yml

Navigate to project folder from cmd line & run cmd 
docker-compose up -d it will download all the container for current project. It will check the default docker-compose.yml file
docker-compose -f dev-docker-compose.yml up -d : To read specific composer file,

Note : YML format is not required we can use the json also, default docker-compose.yml because YML is actually superset of json.

Steps To Install & manage drupal project with docker-composer : 

1 - Make sure you install the docker & docker-compser
2 - Get the drupal 8 code from github by composer :
composer create-project drupal-composer/drupal-project:8.x-dev some-dir --no-interaction
3 - Now get the files for drupal based docker composer so it will also downlod from the github,
git checkout all the files from this git repository & delete the .git type files because there is not usefull Also delete the docker-compose.override.yml 

4- Now copy & paste all these files in the current drupal root project,
5 - And open the .env file it has all the setting of the project like db credentials, baseurl etc
6- Now run the command docker-composer up -d it will install all the conteners which is dependent on this project when all done then , 
7 - Now all setup just open the baseurl which is defined in the .env file with port like,

Congratulations I got the install page of First Docker drupal !!!









Comments

Popular posts from this blog

How to span column of custom table in Drupal

If you want to span the column of custom drupal table like below image, Follow the below code to make the header of the table , <?php $header = array('S.N','District', array('data' => '<div class ="house">Household </div><br><span>Rural</span> <p>Urban</p>','colspan' => 2), array('data' => '<div class ="house">Members</div> <br><span>Rural</span> <p>Urban</p>','colspan' => 2), 'Duplicate/Failed Registration', array('data' => '<div class ="house">Pending De duplication </div><br><span>Rural</span> <p>Urban</p>','colspan' => 2), 'Non Un-organised Workers', 'SSID Generated', 'No. of Card Personlised', ); $rows[] = arra...

Drupal 8 : Link actions,Link menus,Link Tasks,Routings

Drupal 8 : Link actions,Link menus,Link Tasks,Routings Link actions Local actions have also been moved out of the hook_menu() system in Drupal 8 .Use actions to define local operations such as adding new items to an administrative list (menus, contact categories, etc). Local actions are defined in a YAML format, named after the module they are defined by. Such as menu_ui.links.action.yml for this example from menu_ui module: menu_ui.link_add:   route_name: menu_ui.link_add   title: 'Add link'   appears_on:     - menu_ui.menu_edit Here, menu_ui.link_add: It is the Unique name of the link action Most likely start with module name, route_name : Name of the route it means when click the link it redirect to this route, appears_on :  An array of route names for this action to be display on. Now how to know the Route name of any internal/external admin pages like below, By through the drupal console we achieve it, drupal debug:router...

Cache In Drupal

Drupal 8 core caching modules: The Internal Page Cache module: this caches pages for anonymous users in the database. Pages requested by anonymous users are stored the first time they are requested and then are reused for future visitors. The Internal Dynamic Page Cache module: This is a key feature that Drupal 7 did not have. Unlike the Internal Page module, the Dynamic Page module aims to speed up the site for both anonymous and logged-in users. How Cache Works in Drupal: There are two modules available in the drupal core 1 - Internal page cache: The Internal Page Cache module caches pages for anonymous users in the database. Pages requested by anonymous users are stored the first time they are requested and then are reused. Configuring the internal page cache :   From the performance page we can set the maximum time how long browsers and proxies may cache pages based on the Cache-Control header. 2 - Internal dynamic page cache: Drupal 8 provides the Dynamic Page Cache m...