Developing with Docker - Docker in Practice || Docker Tutorial 8
Skills:
Docker & Containers90%
Key Takeaways
Develops a Node.js and MongoDB application with Docker
Full Transcript
[Music] so in this video we are going to look at some practical example of how to use docker in a local development process so the prerequisites before you get started with this video is you have to understand some basic concepts of docker and you have to know some of the basic commands so if you don't you can check out my videos where I cover both the concepts and the comments and then you can come back to this video so what we're gonna do is a simple demo of a JavaScript and node.js application in the backend to simulate the local development process and then we're gonna connect it to a docker container with a MongoDB database in it so let's get started so in this video we're gonna see how to work with docker containers when developing applications so the first step will be is we're gonna develop a very simple UI backend application using Java Script very simple HTML structure and no J's in the backend and in order to integrate all of this in the database we are gonna use a docker container of a MongoDB database and also to make working with the MongoDB much easier so we don't have to execute commands and in the terminal we're gonna deploy a docker container of a mongrel UI which is called Express where we can see the database structure and all the updates that our application is making in the database so this development setup should give you an idea of how docker containers are actually used in development process so I've already prepared some very simple JavaScript application so in order to see the code basically we have this index.html that is very simple code and we have some JavaScript here and we're using node.js back-end that just serves that index.html file and listens on port 3000 so we have the server running here in the backend and we have the UI that looks like this so basically it's just the user profile page with some user information and user can edit their profile so if I for example change the name here and if I change the email address and do changes like this I can save my profile and I have my updates here however if i refresh the page of course the changes will be lost because it's just JavaScript no J's so there is no persistent component in this application so in order to have that which is actually how real-life applications work you'll know that you need to integrate the application with the database so using that example I will try to showcase you how you can actually use the docker containers to make the development process easier by just pulling one of the databases and attaching it or connecting it to the application so in this case we're gonna go with the MongoDB application and in addition to MongoDB container we're gonna also deploy a MongoDB UI which is its own container it's called Express where we can manage or see the database in insights and updates from our application much easier so now let's see how that all works so in order to get started let's go to docker hub and find our MongoDB image here let's go to Congo and we have MongoDB here and the Express which is another container that we're gonna use for the UI so first let's pull the MongoDB official image so I already have MongoDB latest so pulling doesn't take longer but on my laptop but you're gonna need a couple of seconds probably and the next one we're gonna pull is the docker Express which I also have I believe so let's see yes it's also fast so if I check luckily I have MongoDB and Express images so the next step is to run both and Express containers in order to make the MongoDB database available for our application and also to connect the Express with the DB container so let's do the connection between those two first in order to do that we have to understand another darker concept doctor network so how it works is that Dhaka creates its isolated token network where the containers are running in so when I deploy two containers in the same token Network in this case and Express they can talk to each other using just the container name without localhost port number etc just the container name because they are in the same network and the applications that run outside of docker like our node.js which just runs from node server is going to connect to them from outside or from the host using localhost and the port number so later when we package our application into its own docker image what we're gonna have is a game token network with MongoDB container Express container and we're gonna have a node.js application which we wrote including the index HTML and JavaScript for fronting in its own docker container and it's gonna connect to the MongoDB and the browser which is running on the house but outside the docker network is going to connect to our JavaScript application again using hostname and the port number so docker by default already provides some networks so if we say docker Network LS we can already see these auto-generated dog networks so we have four of them with different names and the drivers we're not gonna go into details here but what we're gonna do is create its own network for the MongoDB and Express and we're gonna call it mobile network so let's do this right right away I'm gonna say docker Network create and we're gonna call it Network so now if I do doctor Network LS again I see my token network has been created so now in order to make our MongoDB container in the Express container run in this Mangal Network we have to provide this network option when we run the container in the docker run command so let's start with the so we all know that docker run is the command to start a container from an image right so we have current which is the basic docker run command however in this case we want to specify a couple of things as you learned from the previous videos you have to specify something called port so we need to open a port of MongoDB the default port of MongoDB is 27 thousand seventeen so we'll take that port actually for both host and container so will run at this port inside of a container and we open the same port on the host so that will take care of the port then we will run it in a detached mode in addition to that there are a couple of things that we can specify when starting up the container and these are environmental variables of the MongoDB let's see in the official image description you actually have a couple of documentation about how to use the image which is very helpful to kind of understand what kind of configuration you can apply to it here you see some environmental variables so basically on startup you can define what the root username and the password will be which is very handy because we're gonna need those two for the experts to connect to the and you can also specify the init database we're just gonna provide the username and password because we can create the database from the Express you why later so let's do that and the way you can specify the environmental variables you can actually see here as well is by just let's copy this one so here you say environmental variable that's what they - e flag stands for and the root username will say it's admin and another variable which is the password will be just password so in this way we can actually override what the default username and password will be so two more things that we need to configure in this commend our container name because we're gonna need that container name to connect with the Hmong Express so we'll call this one dB let's say and another one we need is the network that we created which was called Network so in order to make this command a little bit more structured do it on multiple lines so let's see so it's more readable so basically all these options or all these flags that we set to go one more time through them it's gonna start in detached mode we are opening the port on the host username and password that we want a MongoDB to use in the startup process we're gonna rewrite or override the name of the container and this container is gonna run in a Network and this should actually start the container okay so if you want to see whether it was successful we can lock the container and see what's happening inside so as we see was started and everything actually looks good waiting for connections on port 20 7017 okay so now let's start Express we want Express to connect to the running MongoDB container on startup and here we have an example of how to run it and here we have a list of environmental variables that we can configure so let's quickly look at them username password we don't need them however we need the admin username and admin password of the MongoDB this is actually what we overrode with admin and password so we're gonna use them because Express will need some username password to authenticate with the MongoDB interconnected the port is by default the correct one so we don't need to change that and this is an important part this is the MongoDB server right so basically this is the container name that experts will use to connect to the docker and because they are running in the same network only because of that this configuration will work if I didn't if I hadn't specify the network then I could have I could specify the name correct name here of the container but it wouldn't work so with that said let's actually create the docker run command for express as well so let's clear the history and let's start so again we run in detached mode and let's see what parameters we need so first of all port let's say with what is the default port that the Express runs on that's 80 81 so we'll take that so basically it's gonna run on our laptop on port 80 81 the next option would be these two and remember environmental variables need to be specified with minus E and this is the username of MongoDB admin which is admin because we specified it when we started the MongoDB container this is the password let's set this one as well don't forget the network - - net Network we have the name we can also call it Express and let's see what else we might need here yes this is important one and our container name let's actually see it again dr. PS the one running it's called MongoDB that's the container name and this is what we need to specify here so I'm gonna write this here and finally the image is called Express so I'm just gonna copy this one here and that is it so basically with these commands talk Express should be able to connect to the MongoDB container so let's write it and just to make sure let's lock the container and see what's happening there waiting for MongoDB welcome to my express it looks like it connected successfully it says here database connected and the Express is available at port 8081 so let's check the manga Express out at the port 8081 so actually let's close these tabs you don't need them anymore and here if I say localhost 8080 one I should be able to see the manga Express so these are the databases that are already exist by default in or which are created on startup and using the UI we can create our own database as we saw previously we could have specified an environmental area variable in it TB on MongoDB startup and that would have created a new database however it doesn't matter we will just create a database name here so we will call it user account database so let's create one and now we can actually use it or connect to this database from nodejs so let's see how that works so now we have the MongoDB container and the manga Express container running so let's check that we have both of them we'll have to connect no J's with the database so the way to do it is usually to give a protocol of the database and the URI and the URI for a MongoDB database would be localhost and the port that it's accessible at so when I already went ahead and prepared the code for no J's so basically we are gonna use a client here which is a node module and using that client we are connecting to the MongoDB database so this is the protocol the host and the port that we just saw that the MongoDB is listening at and username and password of the root user of MongoDB of course usually you wouldn't put the password here or not use an admin or root username password to connect to a database but this is for just the demonstration purposes and these are username and password that we set as environmental variables when we created the docker MongoDB container so let's check that so this is the MongoDB container command and this is the username root and root password that we specified and this is what we are gonna use in the code as I said for demonstration purposes I will write the password directly here so then we connect to the database so I also went ahead and in the Express user account database and inside that I created collection which is like a table in my sequel world called users so here I connect to a user account database and I query the collection users and this is a get requests so I'm just fetching something from the database and this is update request same thing I connect to the database using the same URI and the database name and I update or insert something in the collection so let's see how all that works so let's head over to the UI so in the users collection the there is no data it's empty so we're gonna refresh it and edit the data so I'm gonna right here some and update it and refresh we see that a new insert was made so this is the update profile section here so all this was executed it connected to the MongoDB and now we have one entry which is email coding name that we changed so if I'm gonna refresh it now I fetched a newly inserted use the data in the UI and I displayed it here and also if you want to see what the MongoDB container actually logs during this process we can actually look at the locks so I'm gonna say docker PS and block using the container ID so let's say if I wanted to see just the last part of it because I wanted to see what the last activity was I can also let's clear this and I can also do tail so I can just display the last part of it or if I wanted I could also stream the logs so I'll clear this again and I'll say stream the logs so I don't I won't have to do doctor logs all the time so if I make a line here for example to mark the last logs I can refresh it let's make some other changes let's change it and save profile so I'm gonna see some activity here as well so these connections are new and it also says received client metadata and this is where the node.js request comes in with a noches and it's version and at the end of each communication there is an in connection because we end the database connection at the end so we see that also in the logs so for example something wasn't working properly you could always check them in a logs here so with that I have a fully functional JavaScript node.js application which has a persistence in the MongoDB database and we also have UI both of them running in a docker container so this would be somehow a realistic example of how local development using docker containers would look like thanks for watching the video I hope it was helpful and if it was don't forget to like it this is a video series so I will create a new one every week so if you want to be notified whenever a new video comes out then subscribe to my channel if you have any questions if something wasn't clear in the video please post them in a comment section below and I will try to answer them so thank you and see you in the next video
Original Description
How to develop an application with Docker. This is a practical tutorial building a simple Javascript application with Node.js and MongoDB using Docker.
Once you've learnt the basic concepts, it's important to see how Docker is actually used in practice or in real world development so to say.
In this video I show you how to work with Docker containers when developing applications. So, this will be a demo of developing a simple UI with JavaScript and Nodejs in the backend and connecting it with a Docker Container with a Mongodb database
The code on gitlab: https://gitlab.com/nanuchi/techworld-js-docker-demo-app
▬▬▬▬▬▬ T I M E S T A M P S 🐳
0:00 - Intro
0:14 - Pre-Requisites
0:55 - what we will do in this video
1:44 - 1st part: The JavaScript App (HTML, JavaScript Frontend, Node.js Backend)
3:30 - 2nd part: MongoDB and Mongo Express Set-Up with Docker
5:00 - Docker Network concept and demo (docker-compose uses docker network under the hood, in the next video(s) I will show you how to do it with docker-compose)
15:33 - 3rd part: Connect Node Server with MongoDB container
"Docker in Practice" series:
Developing with Docker ► https://youtu.be/6YisG2GcXaw
Docker Compose ► https://youtu.be/MVIcrmeV_6c
Dockerfile ► https://youtu.be/WmcdMiyqfZs
Private Repository ► https://youtu.be/vWSRWpOPHws
Deploy your containerized Application ► https://youtu.be/ZowjOhpAcIc
You can check out my videos for the Pre-Requisites:
✅ Basic Docker Concepts: https://youtu.be/GeqaTjKMWeY
✅ Basic Commands: https://youtu.be/xGn7cFR3ARU
For any questions/issues/feedback, please leave me a comment and I will get back to you as soon as possible.
►► Full Docker and Kubernetes Tutorial Playlist: https://bit.ly/2YGeRp9
This video is the 8th of a complete series for beginners, where I explain the ba
Playlist
Uploads from TechWorld with Nana · TechWorld with Nana · 8 of 60
1
2
3
4
5
6
7
▶
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Docker? Docker container concept explained || Docker Tutorial 1
TechWorld with Nana
What is a Docker Container? Docker Demo || Docker Tutorial 2
TechWorld with Nana
How to install docker? Step by Step || Docker Tutorial 3
TechWorld with Nana
8 Basic Docker Commands || Docker Tutorial 4
TechWorld with Nana
Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
TechWorld with Nana
Docker vs Virtual Machine | simply explained || Docker Tutorial 6
TechWorld with Nana
Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
TechWorld with Nana
Developing with Docker - Docker in Practice || Docker Tutorial 8
TechWorld with Nana
Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
TechWorld with Nana
Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
TechWorld with Nana
Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
TechWorld with Nana
Docker Volumes explained in 6 minutes
TechWorld with Nana
Deploying the containerized application with Docker Compose || Docker Tutorial 12
TechWorld with Nana
Docker Volumes Demo || Docker Tutorial 13
TechWorld with Nana
Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
TechWorld with Nana
What is Kubernetes | Kubernetes explained in 15 mins
TechWorld with Nana
Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
TechWorld with Nana
Kubernetes Architecture explained | Kubernetes Tutorial 15
TechWorld with Nana
Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
TechWorld with Nana
Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
TechWorld with Nana
Top 3 programming languages to learn in 2020 | meta analysis
TechWorld with Nana
Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
TechWorld with Nana
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
TechWorld with Nana
Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
TechWorld with Nana
Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
TechWorld with Nana
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
TechWorld with Nana
Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
TechWorld with Nana
Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
TechWorld with Nana
Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
TechWorld with Nana
Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
TechWorld with Nana
Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
TechWorld with Nana
Kubernetes Ingress Tutorial for Beginners | simply explained | Kubernetes Tutorial 22
TechWorld with Nana
What is Helm in Kubernetes? Helm and Helm Charts explained | Kubernetes Tutorial 23
TechWorld with Nana
How Websites Work | simply explained with examples
TechWorld with Nana
What is JavaScript? | JavaScript Tutorial #1
TechWorld with Nana
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
TechWorld with Nana
JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
TechWorld with Nana
How Prometheus Monitoring works | Prometheus Architecture explained
TechWorld with Nana
Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
TechWorld with Nana
JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
TechWorld with Nana
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
TechWorld with Nana
Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
TechWorld with Nana
Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
TechWorld with Nana
Pull Image from Private Docker Registry in Kubernetes cluster | Demo
TechWorld with Nana
Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
TechWorld with Nana
Yaml Tutorial | Learn YAML in 18 mins
TechWorld with Nana
Terraform explained in 15 mins | Terraform Tutorial for Beginners
TechWorld with Nana
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
TechWorld with Nana
Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
TechWorld with Nana
Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
TechWorld with Nana
Kubernetes Operator simply explained in 10 mins
TechWorld with Nana
What is Infrastructure as Code? Difference of Infrastructure as Code Tools
TechWorld with Nana
AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
TechWorld with Nana
Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
TechWorld with Nana
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
TechWorld with Nana
Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
TechWorld with Nana
Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
TechWorld with Nana
Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
TechWorld with Nana
Containers on AWS Overview: ECS | EKS | Fargate | ECR
TechWorld with Nana
Kubernetes is dropping Docker support - What does it mean for YOU?
TechWorld with Nana
More on: Docker & Containers
View skill →Related Reads
📰
📰
📰
📰
Java Strings Explained: Immutability, String Pool, StringBuilder, StringBuffer, and What Really…
Medium · Programming
localStorage, sessionStorage and cookies: The Auth Token Decision Most Tutorials Get Wrong
Medium · JavaScript
How to Parse TOML in the Browser Without a Backend
Dev.to · ggwork
I Negotiated 6 Backend Engineering Offers in 2026. Here Is the Data Nobody Publishes.
Medium · Programming
Chapters (7)
Intro
0:14
Pre-Requisites
0:55
what we will do in this video
1:44
1st part: The JavaScript App (HTML, JavaScript Frontend, Node.js Backend)
3:30
2nd part: MongoDB and Mongo Express Set-Up with Docker
5:00
Docker Network concept and demo (docker-compose uses docker network under the
15:33
3rd part: Connect Node Server with MongoDB container
🎓
Tutor Explanation
DeepCamp AI