Install Postgres Using Docker Compose | Docker | Postgres

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello people welcome back to my channel and let's learn how we can do postgress installation using Docker compose so postgress is a rdbms that is relational database and it is used in uh large scale production system and you can also use it in your hobby application so we'll be learning the quickest way to install postgress using Docker because Docker is operating system agnostic and you can do installation within minute so let's learn what we are going to do so there are some prerequisities that needs to be fulfilled the first one is Docker must be installed and then we have Docker compose must be installed so what we are going to do is we will be having this blog post which I have already written that is uh install Docker on your machine I'll post this link in the description below and here you can see we have installed Docker using Windows using Ubuntu that are different ways through which you can install and the version of operating system I'll add more um new things to it like more new block post related to different operating system and you can follow one of them whichever suits for your operating system so this is one block that you need to follow next what we are going to do let's understand how it is going to work so there's a host operating system and it can be windows in my case it can be Ubuntu in your case anything so this is the main operating system that is installed and when you install Docker so there's already a virtual environment created and inside the virtual envir environment we have Docker containers which are deployed so what we are going to do we'll create a postris Docker container here and then we'll expose Port 5432 inside the docker container environment and same will be mapped to 5432 outside the docker container environment so that any person who is on host operating system can access the inner container which is inside Docker using this port so you can connect to this post system using in this port so um I have already written this block post here if you see that is install post using Docker compose you can follow this one also and create your postgress Docker container and start with the database uh so let's see what we are going to do so here we are saying that we'll create a file that is touch postp talker compost. EML and this can be anything the name can be anything whatever you want so let's go to our uh uh terminal and I'll bring my terminal here so inside the terminal what I'm going to do I'll go to workspace and then YouTube playground if I do a LS here you can see there is already a file so now what I'm going to do I'm going to create a new file that is post doer compost EML so once it is created I'll open my visual studio code so visual studio code is here and then I'll open that folder so I will go to file open folder this configuration can be different in your case because you may be having a different ID like intellig or something else this is in my case I'm using visual studio code if you see here the file is present here now let's go to this post and just copy paste it we'll I'll explain it what these configurations are I'll come here and if you can see there is this version 3.8 which says that which version of Docker compose we are using the syntax version for writing the docker compos file because the syntax also changes with release of new version and the services are what like which service or which Docker containers will be created so here we are creating only the postgress docker container and we are using the image post 14.1 which is using Alpine operating system as the base so we will be installing postgress 14 so if a new latest version comes you can just update the tag here this is called as tag like 14.1 Alpine is the tag you can update the tag and you can have your new version of postes restart always means even if it crashes because of some issues it's will automatically restart so these are the different environment variables that we are supplying one is like postgress user and another is postgress password so the username through which you can log in is postgress and the password is also postgress and then this is the port configuration 5432 5432 which we have already seen in our uh slide that we are exposing these two Port we are also creating a volume with the name DP and that is basically mounting to the verely postgress data inside the docker container so why we are creating volume just to save or purist our data if the container get crashed we create a new container we destroy it or something else but still the data will be available like the database that you have created the tables the data that you have inserted everything will be available and we are using the volume driver as the local which is the default one so this is the configuration that we have done let's go to our terminal and see here by doing Docker PS so if you see there is no container there's nothing but if I see Docker images so you can see here that already a post image must have been downloaded because I've been using it for a long time so if I come here so that was rabbit mq MySQL and this is the postgress so if you see the postgress image postgress 14.1 Alpine is already there so um when I'll start the docker container using the docker compose the image will not be uh downloaded because it is already present in our operating system so if you go to the next thing what is that we need to start the services that is using Docker compose hyphen f the name of the docker file and using the up if you supply hyphen D at the end what it will do it will start it in the demon mode like not in the foreground mode we'll see that then these are the configurations and also for accessing the uh postgress container or you can say postgress database you need to have psql client so I am using uban 2 so I'm using this postgress SQL client as the uh Library which I'm downloading and which will give me this psql client okay so let's see what how we are going to do all this so let's go to our terminal again and if I go and do LS you can see the file is already here so I'm saying Docker compose hyphen f and then the name of the file post Docker compose and doing a up so since the image is already present on my local it is not going to pull it but the docker uh container will start and it is saying database system is ready to accept connection so we have already started the Docker container now let's try to connect to it so I've already I'm already having this psql client and if I do hyph H which is the host so 17.0.0 1 is the Local Host which I'm using hyph new post so if you remember in our configuration we have given the postgress user as postgress and the password is also postgress so we'll be using the same so let's do enter and then I will give the password as postgress and I'm inside the postgress database so now if I do slash L which is here used to list the database so you can see these database are already present and this was the last time I had created the database and it is still present here why because the volume which I had created here is still persisting so that's why my data is preserved now let's create a new database so we can say create database and then test just the name will be test so database is created if I do /l so you can see that the database test is present if I do/ C test which means I'm selecting the database and if I do SLT then there are no relations which means that there is no table so this way what we have done we have successfully installed the postgress uh database and we have also logged in into it now if I do contr c so what will happen that let me clear it I will do Docker PS and you can see there's no running container but I if I do Docker PS hyph a you can see that disc container is there and it just exited like it was created a minute ago and it exited 9 seconds ago why because the control C command was supplied by me now if I do Docker compose hyphen app postris Docker compose yl and this time hyphen D so you will see that it is started in background now if you see it is not like I'm having the terminal again and I I can find new command and if I do Docker PS you can see the post is up and running now if I again come here let me close it let me do it again so I'll just open a new terminal and if I do psql Post p s g r s this is the password you can see I'm able to connect to my database so in this way we have successfully created our postest or we have installed the postris database using Docker compose so you can see how easy it was but I'll say that don't use this Docker compose method to do it in production system always have a VM based post system or any assistant system whatever you are using always have a VM Bas that is not a good system design thing okay so hope you like this video hope you like my Channel please share these videos with other people and please subscribe to my channel thank you
Info
Channel: CodeWithRajRanjan
Views: 209
Rating: undefined out of 5
Keywords: docker, docker compose, postgres, postgres installation using docker, postgres docker
Id: wWEBwmtu7ts
Channel Id: undefined
Length: 9min 14sec (554 seconds)
Published: Sun May 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.