Why Need Docker :
To handing this type of situation Docker & vergant is much helpfull.
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 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 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
Post a Comment