What is Docker Compose | How to create docker compose file | How to use Compose

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] hello and welcome to this session on docker compose this is going to be a very basic and beginners session so in case you do not have any knowledge on docker compose do not worry we will go very basic step by step and learn what is docker compose and why do we use it we will learn how to install docker compose how to create docker compose files and we will also learn how to use these files to create services how to bring up services how to bring down services using docker compose and all the basic commands and some tips and tricks so let's get started and step number one is we have to install docker compose and before actually i do step number one let us uh very quickly see what is docker compose and why do we need it so i have written some nodes here so docker compose is a tool for defining and running multi-container docker applications so in our earlier sessions we have already seen if i go to uh docker hub and i go here hub.docker.com and i have already signed in i will go to explore repositories and yes so you can see these are there are these lot of images here and using these images we can actually create containers in docker and this is something we have already learned in this series up till now however in real world we need to create complete applications that will be using different services and they need to interact with one another one good example to understand this is micro services let me show you a micro services example and i will go to images and here let me use this image this is a very good example so yes let us see this online shopping service so you can take an example of amazon.com or any online shopping service it has multiple modules like account service product catalog card service order service users and so on now in microservices we have a separate application and a separate database so account service will have its separate database separate application separate servers similarly the product catalog will be separate so that whenever we want to make any changes in one module we do not have to touch any other module and scaling up is very efficient suppose my products range have increased tremendously and i need a larger database so i just have to increase the size of products database and will not be touching any other now this kind of an application architecture if you want to create with docker we need to use something like docker compose so it is a tool for defining and running multi-container docker applications we use yaml files to create these configuration files which is named docker hyphen compose dot yml and i will just show you how exactly this is done in a moment we can start all the services with a single command we can stop all the services with a single command and we can scale up selected services whenever required and i will just show you how this is done so let me go to step number one and it is install docker compose now in case you are on windows and mac it is already installed with docker so once you install your docker on windows or mac this docker compose is already there so you can go to your command line i'm on mac i'm going to my terminal if you are on windows you can go to your windows command prompt or powershell and if you are on linux you can use your linux command line and run the command docker compose minus v and this should show you your docker compose version if it does not show you the version that means docker compose is not installed you can also say docker compose space version and it will show you all these details or docker hyphen compose space hyphen hyphen version which is equivalent to the first command and it will again show you the version for docker compose so in case you are on windows and mac most probably it will already be installed and here the commands to check it and in case it is not installed or you are on linux there are two ways to install so the first way is you can go to this uh github page for docker compose and i will make this link available you can go here on this page and here whatever latest version is you can get that using these two commands so the commands are here so you have to run these two commands to get docker compose and here you can see this is the version and you can provide any version here and then of course you can make the changes in the permissions by using this command so this is one way second way is we can get it using pip using the command pip installed mines you docker compose so if you have python and pip installed on your system you can also get it from here or the direct ways you can get it from this link and run the commands available there and then of course you can check by running the commands docker compose version or docker compose space minus v and it should show you the docker compose version so this was step number one now step number two is we have to create docker compose file at any location on your system and the name of the file will be the standard name is docker hyphen compose and with extension dot yml so what i'm going to do is i will create a new folder on my desktop and create a new file and for the benefit of people who are following this tutorial on a command line operating system like linux i will do it from the command line itself so what i'm going to do is i'm going to go to my desktop now i am on my desktop i will clear the terminal and i will say i will make a directory docker compose file so you can see this folder docker compose file is created and i will go inside this file inside this folder and here i will just create a new file by the name docker hyphen compose dot yml and yes this is created and i will edit this file by the vi editor and yes so now i am inside i will press i on my keyboard to go into the insert mode and here what we do is we say services so we define services and then i will give two spaces and let us say we have to create a web application so the very basic things we need is a web server and our database so if i go to my docker hub so let us say we have a lot of web application servers and let me use engines engines is a very popular web application server if i go to the details here so you can see this is an open source reverse proxy server for http https and so on so what i will say is i want to give any name to my service i am giving this web and then i will say the image that it has to take it from is engines okay and then i will say the other service is a database and then again i have to say what is the image and i am saying the image it has to take it from is we can use any database so for example we have mysql here and then we also have a red so that is a very fast key value data store so i will say take the image from redis and for now let me just use this and i will press escape and say colon w q to right and cute and exclamation and come out so i can say cat and see my docker compose yml file and here it is and also you can see physically it is created here docker compose files and this is the file okay so now the next step you have to do is which is step number three is check the validity of file by command docker hyphen compose config so this is the command that will check the validity of our file so before running the docker compose command i will use this so i will say so i am already in the directory where my docker compose dot yml file is i will say docker compose config so here i am getting some error the docker compose file is invalid because unsupported config option for services so let me just check my file again so the things are looking okay to me uh what i can do is i can give a version here so i say version equals one and i will just explain you what i'm doing i will save and close this and i will say again docker compose config and here it is saying a version in docker compose yml is invalid you might be seeing this error because you are using the wrong compose file version and you can read more about this here so let me show you what is the problem if i go to this particular url which is the docker.com documentation here you can see about this compose file details and here is the compose file version so you have different versions and then you have to see what version will support your docker compose so what i will do is i had given version one i will change this to version three and save and close and let me run this again docker compose config and yes so if you are lo seeing the contents of your file that means now it is fine and now you can actually start running this so now step number four is run docker compose.yml file using the command so the command is docker compose up and i will say minus d flag to start this in a detached mode so i will say docker compose up this is the command to run the yml file and to create the containers and application and i am using minus t so that it starts it in a detached mode and i have the terminal available for writing other commands so i will say enter and you can see it is pulling engines image now because it is not locally available and downloading it and now it is pulling the database redis and again downloading it now this is done so you can see everything is complete i can clear my terminal and if i say docker ps now you can see we have two containers running one is our engines that is the web application server and then we have our database which is the redis so we have this running and now you can see how easy and quick it was and if i want to stop this i can just say docker compose down and it will stop everything so you can see everything is stopped and if i say docker ps now you can see there is no container everything is removed so how quick and easy it can be now of course uh let me show you if i go to docker hub and let me just go to uh this engine's image we used so if i go to the details uh and i go to the compose section so you can see they have already given an example of a docker compose yml file and of course what i have shown you this particular file this is a very bare minimum file just for demo purpose of course you will be needing a lot of other things like exposing the ports attaching a volume and so on so let us say if i use this i am exposing the port and i can use this so i am saying what i am saying here is expose the port 80 of the web server and expose it on port 8080 on my host machine or let me say this is 1990 on my host machine i will save this close this and run my docker compose again and before i do that i will run the config command to just check the validity and there is some problem so let me just see again uh let me see if i do not give this here and i see yes it is okay now so now i will just close my file and here i will say docker compose up minus t and this time because it already had the images it has just started our containers and if i say docker ps it is up and now i can go to my browser and i can go to localhost 1990 and you can see our nzx application is up and running so i will just make this down now i'll say docker compose down and everything is stopped i say docker ps and nothing is running let me clear my terminal and also let me write down the steps here so step five is bring down application by command docker compose down and in the tip section i just want to show you how to scale services so basically if you are using something like microservices we saw here and you want to scale some particular service so for example you have created your services by using multiple containers databases and you just want to scale some particular service so how do you do that so you can use something called as scale flag and actually if you say docker compose and say minus minus help and run this command you will actually see all these options here and here you have this option scale which is set number of containers for a service so this is what we are going to do here so what we are going to do is we will say docker compose up minus t in detach mode and now we will use the flag minus minus scale and we have to tell which service to scale and to how many number or or to how many continuous have to be created so if i look at my docker compose yml file i have a web service and a database service so what i will do is i will say that the database service i want to create four instances okay and i will just run this and you can see it is creating four databases instances for us and if you say docker ps now you can see we have a single web application server which is nginx and then we have four redis okay four databases so i will again bring everything down and clear and if i say docker ps everything is down and removed now so let me also copy this command and all this will be available in the notes section of this video so this is how you use docker compose in a very quick and easy way of course when you work with enterprise application you will be using a lot of other commands and instructions in your docker compose by ml file but with this particular session you have all the knowledge of docker compose how do you create docker compose files how do you run them to create services how do you bring them down and how do you scale applications with docker compose so i hope this session was very useful for you i will meet you in the next episode of docker thank you for watching [Music] you
Info
Channel: Automation Step by Step
Views: 439,456
Rating: undefined out of 5
Keywords: what is docker compose, how to use docker compose, how to create containers with docker compose, how to intall docker compose on, how to create docker compose file, docker compose basic commands, docker compose beginner tutorial, docker compose introduction
Id: HUpIoF_conA
Channel Id: undefined
Length: 18min 23sec (1103 seconds)
Published: Mon Jul 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.