what an informative video, i don't know much about docker but i was able to understand what docker compose does in just a few minutes into the video. you add yourself a subscriber
Damn!! i'm not even a speaker of your language, and still got the whole ideia.Nice vídeo my friend, you earned a new subscriber!! Hope now i'm going to be able to absorb this whole docker thing
Excellent video, however I had to add the following 2 lines under docker-compose file to get things working; Under "react-app:" add > build: ./client Same for "api-server:" add > build: ./server Thanks
Thanks @Farzad! I build the images separately (before running docker-compose up) which is why I was able to use just the "image" name in the docker compose file!
Thanks @Chief Terrible Teacher! I'm planning to do a follow up soon where I take the same setup and make some tweaks to make it more suitable for deployment (since this video shows a development configuration) Stay tuned!
Another new software RUclipsr ItGuyMichal coincidentally released a docker-compose video yesterday as well (ruclips.net/video/UBFiCfbRykE/видео.html) His is a longer form tutorial (~40 min) where he walks through setting up docker-compose for configuring Postgres, pgAdmin, and Jupyterlab to work together. If you are looking for a more in-depth explanation/walk through, definitely check out his video and channel!
Yes, that is a good point. That way if you ever prune all the dangling docker resources the data can still persist! Since this is just a development setup it's not too critical, and if deploying a configuration like this you probably don't want to run the DB in docker at all!
After changing the mondb url from localhost to mongo where I can see it in mongodb compass because iam not able see the data stored after changing it to mongo
Thanks for the amazing tutorial. I am learning docker, your video really helped me learn to dockerize the MERN app. But the I am not able to add movie. when i open localhost:5000 i get "Hello world" as result. Please help me understand this
Hi Jack -- For the Dockerfile shown in the video (github.com/sidpalas/devops-directive/blob/master/2020-08-31-docker-compose/docker-compose.yml), I specified the "image" directly so you have to build it first. (using "docker build -t ") If instead, I used the build option like here (gist.github.com/sidpalas/850a08326f46839057f611c05fa14f59), then docker-compose could automatically build the images before running. Here is the documentation for the build configuration option docs.docker.com/compose/compose-file/#build Does that help?
Hey @Shekhar -- I'm glad it helped! I have implemented a few hot reloading docker configurations durin live streams on the channel, but it might be woth creating a dedicated video about how to use volume mounts to allow source code changes to be represented inside the container in real time.
If by " scale" you mean "run multiple copies of", Docker compose isn't really designed for that. For managing lots of replicas of your application containers you want an orchestrator like docker swarm, hashicorp nomad, or kubernetes. You could also deploy multiple copies of the container yourself but once you go beyond a single machine, you will end up hacking together your own version of an orchestrator 😆
Linux namespaces (used to confine what a process can see) and cgroups (used to limit the amount of resources a process can use) are the key! Docker came along and make the user experience for using these much nicer! 😀
I'm new to deploying apps. Why do we containerize our react app? I understand the backend and database, also microservices, but why the front end?? How do you even deploy a containerized front end? Wouldn't you want to just deploy the static files? Clarity on this is appreciated! :)
This is a great question! For deployment: You are correct that you would want to deploy the output of your build step (i.e. the static files it produces). There are lots of ways to do this, one of which would be to bundle those files into a container with something like nginx and deploy that way. If you are already deploying your other applications with a container orchestrator, this allows you to deploy and operate everything in the same way. For development: If you containerize it you can include it within your docker-compose setup so that everyone working on it will share a common setup (rather than needing everyone to have the same versions of all the system dependencies (e.g. node, vite, etc...) Hopefully that helps!
Great question, I actually have been planning a follow up to this video in which I show the steps that I would take before deploying this application. The updated code is already located here: github.com/sidpalas/devops-directive/tree/master/2020-12-21-productionize-mern But I haven't had a chance to film it yet... Feel free to join the channel discord if you have additional questions about the setup! discord.gg/d6geMBSg3M
Hi Pych_1004 -- good question. This is a development setup and is not production-ready. To make it production-ready you would need to do a few things: For the React front end you would want to run npm run build (which builds it into a set of static files). These could then be served with something like nginx (you would probably want to add SSL termination w/in nginx as well to support HTTPS). For the Database, at the very least you will need to configure it with a password, and if the application becomes popular one of the first steps to scaling would be to move the DB off of the same machine as the server (and people debate whether it is a good idea to run a DB in a container for production at all... devops.stackexchange.com/questions/1293/what-are-the-reasons-docker-should-not-be-used-for-databases) Perhaps in the future, I'll do a follow-up video showcasing these steps!
Generally you want to keep each container with a single service. There are some hacks you can do to run multiple things in a single container but it makes things harder to reason about, debug, etc...
Thanks for the great video! Just a small question. I assume the directory structure was something like this: ``` / api-server/ react-app/ ... ``` My question is, what happens if the `api-server` has its own repo? Is cloning the repo into an `api-server` directory and keeping it up to date a viable solution? Thanks!
Great question @andrei! Git actually has a feature called submodules that is designed exactly for this purpose! git-scm.com/book/en/v2/Git-Tools-Submodules You can have a separate repo for each service and the a top level repo that references them!
I don't have any good examples on hand, but that could make a good future video! One example (which is admittedly a bit contrived...) could be if we took the movie MERN application from the video and wanted to add a "predicted rating" feature with an ML model (using inputs such as the title, the list of actors, the budget for the film, etc...). We would wrap our trained model with a lightweight webserver to enable it to accept requests, execute the model, and respond with the results. Once we had that, we would add this new inferencing API as another service within the docker-compose. This architecture is nice because we can use whatever language/dependencies we want for the ML model (independent of our technology choices for the rest of the app)!
Hello! Thank you very much for video! I would like to ask about the best way to work with Windows environment? In that I mean, I have multiple services and front-end applications are already dockerized and working well. But I have one service built on Node, which requires to be running on Windows 2016 server and for that I do all updates each time manually. Could you suggest what wholesome delivery method I can use for these?
While I haven't worked with them, I know there are windows base docker images (hub.docker.com/_/microsoft-windows-base-os-images). This pull request (github.com/nodejs/docker-node/pull/362) shows someone using those base images to create a windows based Node image, but it looks like it hasn't been approved/merged yet. Maybe it will give some guidance on how to achieve what you are hoping for though!
@@stsbmu7169 Report back as you make progress! As I said, I have not worked with Windows based containers, so I'm interested to hear about your experience with them!
@@stsbmu7169 FYI, I recently started a discord server to make discussions like this easier than YT comments. Come join if you want! discord.gg/CHRvYhwvej
nice video sir! i love it, i have one question im getting started with this docker compose thing. how i create an docker image " of all " to upload to my docker hub? i mean i dont want to create an image of my server side, another of my client and pull the mongo one. it is possible to create one only image and pull it all and run?
Hi @luppo2007 -- while you technically could run them all in a single container by adding a custom startup.sh script (or similar) to start the 3 processes is is generally a bad idea. There are a number of reasons for this, explained here: devops.stackexchange.com/questions/447/why-it-is-recommended-to-run-only-one-process-in-a-container
While you could technically run the app without understanding the code, it will be much more useful to you if you do (because you will then be able to modify and extend it to fit your needs)
Good question! It still creates 3 separate containers, it just manages the set up and tear down (+ networking and volumes) with a single command and allows you to specify everything conveniently in one config file!
@@DevOpsDirective is it possible to merge them somehow in order to have one container containing those 3 containers as sub-containers? I'm asking in this with the purpose to eventually push my app to docker hub so as to pull & pull the container from anywhere
@@angelosnm You technically could run all three processes in one container but it would be bad practice. If one of the services had issues it would impact the others and be much harder to work with. It is best to keep each container focused on running 1 thing only.
Hi @Michelle -- It will be quite similar to the code shown in the video, just swapping Vue in for React! You will need to update the "client" implementation with one using Vue. Do you have the application running already without docker-compose?
@@michellegburgosf How is the MEVN app going? FYI, I recently started a discord server to make discussions like this easier than YT comments. Come join if you want! discord.gg/CHRvYhwvej
When running docker-compose up , I stumbled upon this error "ERROR: pull access denied for react-app-dev, repository does not exist or may require 'docker login': denied: requested access to the resource is denied"
This error message means you do not have a docker image with that tag locally so it is trying to pull one from DockerHub. This makes me think you probably did not build the image before running docker compose up!
Adding stdin_open: true is the equivalent of using the -i flag in a docker run command In this case it is kind of a hack to get around this issue: (github.com/facebook/create-react-app/issues/8688). Essentially there was an update earlier this year to React-Scripts that causes the react development server to exit after startup when run inside a docker container (at which point the container shuts down). Adding stdin_open: true tells docker to keep STDIN open even though its not attached to the process which keeps the container alive. This is similar to if you were to run: $ docker run node:slim (the container will start up and immediately terminate) versus if you run: $ docker run -i node:slim (the container will remain up after startup) I hope that helps!
Very helpful!! You are amazing!! very nice explanation! Thank you so much!! You fix my comprehension in just 6 minutes!! Can you make a tutorial with java ee wildfly postgres and angular please.
In this video I swap out the local DB for one running in atlas using an environment variable for the connection URI (ruclips.net/video/DftsReyhz2Q/видео.html) I hope that helps!
Hi @Alberto! In this video I configure this app to use Atlas for the DB and use a .env file ruclips.net/video/DftsReyhz2Q/видео.html Hopefully it helps!
I have a question. What if i made some changes in express js or react js, do I need to type docker compose up again and the application will immediately change?
As configured in the video you would have to rebuild the image first. In my recent livestream (ruclips.net/video/DftsReyhz2Q/видео.html) I showed how to mount the source code into the container using a volume so that changes can be reflected immediately!
So lets say every part of the project runs in its own directory with different github repos. Where exactly does the docker compose file go if there are multiple root directories? Does it go in the root of the front end or the backend? I feel like not understanding something fundamental here.
Good question! For the situation you described I would probably put the docker-compose file at the root of the backend repo and then use the git submodules (www.git-scm.com/book/en/v2/Git-Tools-Submodules) feature to make the frontend repo a sub directory within that repo. If there are even more services (each as their own repo) you could even have a separate integration repo which has all the services as submodules. My preference is just to use a single repo for everything ("Mono-repo") which simplifies your specific question, but adds its own complications elsewhere...
@@DevOpsDirective I was thinking of doing a Mono repos setup myself but wouldn't a large code base of a mono repo present more stability, efficiency, and more importantly scalability challenges? The codebase will be large enough to more than likely suffer from one or more of these issues. "Git fundamentally never really looks at less than the whole repo. Even if you limit things a bit (ie check out just a portion, or have the history go back just a bit), git ends up still always caring about the whole thing, and carrying the knowledge around. So git scales really badly if you force it to look at everything as one huge repository. I don't think that part is really fixable, although we can probably improve on it." -Linus Torvalds
@Andrew -- how big a codebase are you working with? (in either SLOC or team size) The majority of projects will never reach a scale where Git itself becomes the bottleneck. For me, the benefits of being able to more quickly navigate and refactor across the codebase usually outweigh the (slightly) slower sync times or the need to configure CI/CD to be smart about detecting which services have been modified.
@@DevOpsDirective I'm not sure what the SLOC will be because the project is still in the early stages. I'm a few weeks into creating the api using TDD and my endpoint tests alone are almost 5k lines of code. Edit: The tests I have so far are only for about 15 endpoints. I still have at least 30 to go. Hopeful that gives you an idea of the possible app scale.
@@fkw0k3t4rd5 Yeah, I doubt you would have issues with something of that scale. I would choose whichever structure you are more comfortable with and will enable you to move the fastest during this initial development phase.
Great video! I'm learning docker and this was a great resource. Question though: Wouldn't the react-app depend on the api-server the same way the api-server depends on the mongo container?
Great question! You are correct that in order to successfully load the page with the movie results in your browser, the react app needs the API server to be running. The difference is that those requests happen when you load the page not when you start the app! The react app is perfectly happy to start up independent of the other two services, whereas the API server will crash if it can't authenticate to the DB upon start up! I hope that helps!
Thanks @Levelord! You would likely want to specify them as an environment variable. In this video, I show one method of doing this: ruclips.net/video/DftsReyhz2Q/видео.html You can do this in the docker run command or with docker-compose (docs.docker.com/compose/environment-variables/#the-env_file-configuration-option)
RUclips comments are very cumbersome for technical discussions, but if you want to join the channel discord community someone can probably help! discord.gg/ExrENts5CT
Hey man you are amazing , your explanation is clear and simple ,can you make a video on "how to deploy this application on GCP compute engine " thankyou dear
I am getting errors like this. Can you help me out? Pulling mongo (mongo:)... Traceback (most recent call last): File "site-packages\docker\credentials\store.py", line 80, in _execute File "subprocess.py", line 395, in check_output File "subprocess.py", line 487, in run subprocess.CalledProcessError: Command '['C:\\Program Files\\Docker\\Docker\ esources\\bin\\docker-credential-desktop.EXE', 'get']' returned non-zero exit status 1. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "site-packages\docker\auth.py", line 264, in _resolve_authconfig_credstore File "site-packages\docker\credentials\store.py", line 35, in get File "site-packages\docker\credentials\store.py", line 93, in _execute docker.credentials.errors.StoreError: Credentials store docker-credential-desktop exited with "error getting credentials - err: exec: "docker-credential-wincred.exe": executable file not found in %PATH%, out: ``". During handling of the above exception, another exception occurred: Traceback (most recent call last): File "docker-compose", line 6, in File "compose\cli\main.py", line 72, in main File "compose\cli\main.py", line 128, in perform_command File "compose\cli\main.py", line 1078, in up File "compose\cli\main.py", line 1074, in up File "compose\project.py", line 548, in up File "compose\service.py", line 361, in ensure_image_exists File "compose\service.py", line 1250, in pull File "compose\progress_stream.py", line 102, in get_digest_from_pull File "compose\service.py", line 1215, in _do_pull File "site-packages\docker\api\image.py", line 396, in pull File "site-packages\docker\auth.py", line 48, in get_config_header File "site-packages\docker\auth.py", line 324, in resolve_authconfig File "site-packages\docker\auth.py", line 235, in resolve_authconfig File "site-packages\docker\auth.py", line 281, in _resolve_authconfig_credstore docker.errors.DockerException: Credentials store error: StoreError('Credentials store docker-credential-desktop exited with "error getting credentials - err: exec: "docker-credential-wincred.exe": executable file not found in %PATH%, out: ``".') [16672] Failed to execute script docker-compose
Hi Bharath -- Lets first confirm if your Docker Desktop install is working properly. What do you get if you test the docker version ("docker --version")? Also, can you run "docker run hello-world" (which will pull and run hub.docker.com/_/hello-world)?
@@DevOpsDirective Hi there, thanks for response. I figured out the issue. I was running all commands from Git bash in windows instead of Windows command prompt which somehow caused something to go wrong. But then, I ran into another error ( I have also posted it in stack overflow): stackoverflow.com/questions/63903112/mongo-connection-error-mongonetworkerror-failed-to-connect-to-server-localh
@@bharathram3977 FYI, I recently started a discord server to make discussions like this easier than YT comments. Come join if you want! discord.gg/CHRvYhwvej
I'm not sure how this stuff ends up working for people. I'm sure I'm doing something wrong, but it's always endless shots in the dark for me when it comes to Docker. I just want to get back to writing code :(
It is a fairly steep learning curve because of the additional abstraction, but once configured you shouldn't have to touch it much and hopefully will get teams writing code faster!
Amazing video! You explained everything in a very understandable and clear way without oversimplyfing it. Love it
Great to hear -- that is always my goal!
I realize it is kinda randomly asking but do anybody know of a good website to stream newly released tv shows online?
@Lionel Austin I use flixzone. Just search on google for it :)
@Gerald Victor yup, have been using FlixZone for since march myself :)
@Gerald Victor Thank you, signed up and it seems to work :) I really appreciate it!!
I love the pace that you work through things, no filler and everything I need as a devops newb.
This just one video it solves all my problems on MERN. You are a God sent to us. I'm from the Philippines.
Great to hear! Hello from the USA 👋
This video is freaking brilliant. High level yet concise. You have my bell icon being rang.
I finally understood after watching 10 other videos! You are amazing!!
Happy to hear that!
thanks man for saving our time, u explained it very crisp and concise and fully comprehensible
what an informative video, i don't know much about docker but i was able to understand what docker compose does in just a few minutes into the video. you add yourself a subscriber
We have to give a comment for appreciation such an amazing content. So organized, easy to understand.
I appreciate that!
Damn!! i'm not even a speaker of your language, and still got the whole ideia.Nice vídeo my friend, you earned a new subscriber!! Hope now i'm going to be able to absorb this whole docker thing
Amazing! Welcome to the team! 👋👋👋
I have a few other Docker videos as well if you want to check those out.
It's amazing, i feel i learnt way more than 6 minutes. Totally subscribing and recommending this channel! Thank you very much!!
Woo! Thanks, @Rodrigo!
Thanks a lot mate, I was needing this for a project, great job, please keep rocking!!!
Excellent video, however I had to add the following 2 lines under docker-compose file to get things working;
Under "react-app:"
add > build: ./client
Same for "api-server:"
add > build: ./server
Thanks
Thanks @Farzad!
I build the images separately (before running docker-compose up) which is why I was able to use just the "image" name in the docker compose file!
I probably end up watch all your video by end of this weekend . 😀..thanks
Epic!
Depending on which order you watch, you will see the production quality going ⬆️ or ⬇️ and my beard growing or shrinking 🧔
Hey man this video was just the thing I was looking for. Solved some of my queries to! Thanks for the tutorial.
Awesome! Are you building something with docker compose?
@@DevOpsDirective Yeah. I am building my Undergraduate Project with Docker and MERN stack.
Well-made, high-quality video. Subscribed. Well done!
Thank you, Conan! Welcome to the team! 🎉
Concise and super helpful, thanks for sharing!
Thanks @Chief Terrible Teacher! I'm planning to do a follow up soon where I take the same setup and make some tweaks to make it more suitable for deployment (since this video shows a development configuration)
Stay tuned!
Superb. Everything you explained is pretty clear!
Thanks, Nuwan!
Short and knowledge heavy ❤
"Just keep building"
Subbed. Thanks
It's the only way to get better! Welcome to the team!
this is awesome stuff! was able to build my frontend and backend images and execute them with docker-compose. thx!
Glad it helped!
Thanks. This tutorial clarified my mistakes. Amazing Video
Awesome -- I'm happy it helped! 🎉
nice and clear toturial by the way thank you
Very simple precise and perfect you are awesome brother
Thanks @Hafiz! 🎉
Great explanation! Keep teaching👌
Thanks @MJ! I plan to!
Really great concise video
Wow!! Great content. simple and well explained. Thank you so much.
Short informative and simple, thank you for sharing. here's a sub
Thanks, Mehdi! Welcome to the Team! 🎉
thanks for the video, I'm starting to get to know this technology, and I find it super useful, I want to use it with the MERN stack.
You are welcome! Good luck!
THIS MOVIE ACTUALLLY WORKS! Tahnk you very much, now i get it :D
You are welcome!
Wow, amazing video, and congratulations on 500 subs! 🙏
Thanks Kie -- trying to keep up with you! 😎
@@DevOpsDirective Man, you surpass me easily! My upload schedule is a mess right now. :D
Really loved the video !! Helped me a lot thanks !
Amazing -- thanks for watching and for letting me know!
MAN YOU ARE TOO MUCH GOOD
You are a God, thanks so much, you saved my life!
Glad I could help, @Drukan!
Wow this is really helpful!
you're a great guy mate! thanks for the video
Thanks @Darwish, and you are welcome!
THANK YOUU!! very understandable!
You're welcome!
Another new software RUclipsr ItGuyMichal coincidentally released a docker-compose video yesterday as well (ruclips.net/video/UBFiCfbRykE/видео.html)
His is a longer form tutorial (~40 min) where he walks through setting up docker-compose for configuring Postgres, pgAdmin, and Jupyterlab to work together.
If you are looking for a more in-depth explanation/walk through, definitely check out his video and channel!
this is one great video man, keep it up.
Thanks -- will do!
I would suggest to keep close the database mount, not using named volume but directly storing db data into folder
Yes, that is a good point. That way if you ever prune all the dangling docker resources the data can still persist!
Since this is just a development setup it's not too critical, and if deploying a configuration like this you probably don't want to run the DB in docker at all!
I have a question if instead of using the network I use nginx is a correct practice?
Thank you! Awesome! Greetings from Brazil :)
Thanks @Jeliel! 👋👋
Awesome! Amazing explanation, thank you!
You are welcome!
thanks, short and to the point
You are welcome, @Alrz! 🎉
Nice video! 👍 Im using docker compose daily to spin up my dev environment that includes e.g. node, postgres, redis and react.
It's a game changer, isn't it? Up and running with a single command!
@@DevOpsDirective Yea for sure, fast and easy!
simple and clear.great !!!
Thanks @girls in code! 🥳
Good Video, pleasant voice!
Thanks @Ced!
After changing the mondb url from localhost to mongo where I can see it in mongodb compass because iam not able see the data stored after changing it to mongo
Perfect!!!
Thank you very much.
👌-- you are welcome @Balog!
Thanks for the amazing tutorial. I am learning docker, your video really helped me learn to dockerize the MERN app. But the I am not able to add movie. when i open localhost:5000 i get "Hello world" as result. Please help me understand this
I am confused, so before using docker-compose up, do we need to separately build the images for client and server?
Hi Jack -- For the Dockerfile shown in the video (github.com/sidpalas/devops-directive/blob/master/2020-08-31-docker-compose/docker-compose.yml), I specified the "image" directly so you have to build it first. (using "docker build -t ")
If instead, I used the build option like here (gist.github.com/sidpalas/850a08326f46839057f611c05fa14f59), then docker-compose could automatically build the images before running.
Here is the documentation for the build configuration option docs.docker.com/compose/compose-file/#build
Does that help?
@@DevOpsDirective That absolutely helps :) Thanks for clearing my doubt
@@jackedelic9188 Great! Thanks for watching the video and being a part of the community.
Keep the comments and questions coming!
@Mr 3xclamtion Good point!
What a great video!!!
How to change ip address with docker-compose instead of
hardcoding
Great video, finally managed to make a monorepo work with docker but I want to know how to enable live reloading with this for development.
Hey @Shekhar -- I'm glad it helped! I have implemented a few hot reloading docker configurations durin live streams on the channel, but it might be woth creating a dedicated video about how to use volume mounts to allow source code changes to be represented inside the container in real time.
@@DevOpsDirective That's great, I'll also check out your other vids.
Thank you for this video. So how do you scale your containers if you want to scale after using docker compose?
If by " scale" you mean "run multiple copies of", Docker compose isn't really designed for that. For managing lots of replicas of your application containers you want an orchestrator like docker swarm, hashicorp nomad, or kubernetes.
You could also deploy multiple copies of the container yourself but once you go beyond a single machine, you will end up hacking together your own version of an orchestrator 😆
@@DevOpsDirective Ok I asked because I'm thinking of how companies scale their container databases
What was it that made Docker and the whole idea of containerization possible?
Linux namespaces (used to confine what a process can see) and cgroups (used to limit the amount of resources a process can use) are the key! Docker came along and make the user experience for using these much nicer! 😀
I'm new to deploying apps. Why do we containerize our react app? I understand the backend and database, also microservices, but why the front end?? How do you even deploy a containerized front end? Wouldn't you want to just deploy the static files? Clarity on this is appreciated! :)
This is a great question!
For deployment: You are correct that you would want to deploy the output of your build step (i.e. the static files it produces). There are lots of ways to do this, one of which would be to bundle those files into a container with something like nginx and deploy that way. If you are already deploying your other applications with a container orchestrator, this allows you to deploy and operate everything in the same way.
For development: If you containerize it you can include it within your docker-compose setup so that everyone working on it will share a common setup (rather than needing everyone to have the same versions of all the system dependencies (e.g. node, vite, etc...)
Hopefully that helps!
Let me ask, if I do as you do, how can I connect to moongoseDb conpass to check the data? Thank you very much.
Excellent 👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻
What should we care if we want to use this docker compose file in production mode?
Great question, I actually have been planning a follow up to this video in which I show the steps that I would take before deploying this application.
The updated code is already located here: github.com/sidpalas/devops-directive/tree/master/2020-12-21-productionize-mern
But I haven't had a chance to film it yet... Feel free to join the channel discord if you have additional questions about the setup!
discord.gg/d6geMBSg3M
Great content, thank you.
Glad it was helpful, @antonio! 🎉
Great explanation, but I have some question:
Do I have to use NGINX and/or pm2 with this setup? Or is this production-ready?
Hi Pych_1004 -- good question. This is a development setup and is not production-ready.
To make it production-ready you would need to do a few things:
For the React front end you would want to run npm run build (which builds it into a set of static files). These could then be served with something like nginx (you would probably want to add SSL termination w/in nginx as well to support HTTPS).
For the Database, at the very least you will need to configure it with a password, and if the application becomes popular one of the first steps to scaling would be to move the DB off of the same machine as the server (and people debate whether it is a good idea to run a DB in a container for production at all... devops.stackexchange.com/questions/1293/what-are-the-reasons-docker-should-not-be-used-for-databases)
Perhaps in the future, I'll do a follow-up video showcasing these steps!
@@DevOpsDirective +1 on this, would love to see how to make a set up like this production ready
@@bryanmullen4462 Awesome -- thanks for the input. I will put it into the backlog of future video ideas!
Very useful!
Glad to hear that, @Hòa!
Noob question here, do you have 1 container that contrains all services (réaction, mongo, api) or we have one container per serice?
Generally you want to keep each container with a single service. There are some hacks you can do to run multiple things in a single container but it makes things harder to reason about, debug, etc...
@@DevOpsDirective Thank you for your answer. last one, is docker compose an orchestration then? how does it defer from kubernetes?
Thanks for the great video! Just a small question. I assume the directory structure was something like this:
```
/
api-server/
react-app/
...
```
My question is, what happens if the `api-server` has its own repo? Is cloning the repo into an `api-server` directory and keeping it up to date a viable solution?
Thanks!
Great question @andrei!
Git actually has a feature called submodules that is designed exactly for this purpose! git-scm.com/book/en/v2/Git-Tools-Submodules
You can have a separate repo for each service and the a top level repo that references them!
@@DevOpsDirective That's great! I've heard of them in the past and always wondered what they're for. Not it's time to look into it, thanks!
Do you have an example of a docker compose for the ml stack?
I don't have any good examples on hand, but that could make a good future video!
One example (which is admittedly a bit contrived...) could be if we took the movie MERN application from the video and wanted to add a "predicted rating" feature with an ML model (using inputs such as the title, the list of actors, the budget for the film, etc...).
We would wrap our trained model with a lightweight webserver to enable it to accept requests, execute the model, and respond with the results. Once we had that, we would add this new inferencing API as another service within the docker-compose.
This architecture is nice because we can use whatever language/dependencies we want for the ML model (independent of our technology choices for the rest of the app)!
Excellent!!thank!
You are welcome, Ana!
Hello! Thank you very much for video! I would like to ask about the best way to work with Windows environment? In that I mean, I have multiple services and front-end applications are already dockerized and working well. But I have one service built on Node, which requires to be running on Windows 2016 server and for that I do all updates each time manually. Could you suggest what wholesome delivery method I can use for these?
While I haven't worked with them, I know there are windows base docker images (hub.docker.com/_/microsoft-windows-base-os-images).
This pull request (github.com/nodejs/docker-node/pull/362) shows someone using those base images to create a windows based Node image, but it looks like it hasn't been approved/merged yet. Maybe it will give some guidance on how to achieve what you are hoping for though!
@@DevOpsDirective Thank you very much! I will do more studying on it
@@stsbmu7169 Report back as you make progress! As I said, I have not worked with Windows based containers, so I'm interested to hear about your experience with them!
@@DevOpsDirective I will do!
@@stsbmu7169 FYI, I recently started a discord server to make discussions like this easier than YT comments. Come join if you want! discord.gg/CHRvYhwvej
nice video sir! i love it, i have one question im getting started with this docker compose thing. how i create an docker image " of all " to upload to my docker hub? i mean i dont want to create an image of my server side, another of my client and pull the mongo one. it is possible to create one only image and pull it all and run?
Hi @luppo2007 -- while you technically could run them all in a single container by adding a custom startup.sh script (or similar) to start the 3 processes is is generally a bad idea.
There are a number of reasons for this, explained here: devops.stackexchange.com/questions/447/why-it-is-recommended-to-run-only-one-process-in-a-container
ERROR: In file './docker-compose.yml', service 'image' must be a mapping not a string
Do I need to understand coding part for building thia docker compose file
While you could technically run the app without understanding the code, it will be much more useful to you if you do (because you will then be able to modify and extend it to fit your needs)
So basically docker compose creates a container with several images? Or does it still create 3 sepparate containers?
Good question!
It still creates 3 separate containers, it just manages the set up and tear down (+ networking and volumes) with a single command and allows you to specify everything conveniently in one config file!
@@DevOpsDirective is it possible to merge them somehow in order to have one container containing those 3 containers as sub-containers? I'm asking in this with the purpose to eventually push my app to docker hub so as to pull & pull the container from anywhere
@@angelosnm You technically could run all three processes in one container but it would be bad practice. If one of the services had issues it would impact the others and be much harder to work with.
It is best to keep each container focused on running 1 thing only.
hi Sam!
Your video is amazing. Could u pls help me use MEVN application for the same? Are The steps so different than MERN? Thank you
Hi @Michelle -- It will be quite similar to the code shown in the video, just swapping Vue in for React! You will need to update the "client" implementation with one using Vue.
Do you have the application running already without docker-compose?
@@DevOpsDirective Thank you so much :)
@@michellegburgosf You are welcome -- Let me know if you run into issues getting it up and running!
@@michellegburgosf How is the MEVN app going? FYI, I recently started a discord server to make discussions like this easier than YT comments. Come join if you want! discord.gg/CHRvYhwvej
When running docker-compose up , I stumbled upon this error "ERROR: pull access denied for react-app-dev, repository does not exist or may require 'docker login': denied: requested access to the resource is denied"
This error message means you do not have a docker image with that tag locally so it is trying to pull one from DockerHub.
This makes me think you probably did not build the image before running docker compose up!
Can you elaborate on the stdin_open option?
Adding stdin_open: true is the equivalent of using the -i flag in a docker run command
In this case it is kind of a hack to get around this issue: (github.com/facebook/create-react-app/issues/8688).
Essentially there was an update earlier this year to React-Scripts that causes the react development server to exit after startup when run inside a docker container (at which point the container shuts down). Adding stdin_open: true tells docker to keep STDIN open even though its not attached to the process which keeps the container alive.
This is similar to if you were to run:
$ docker run node:slim
(the container will start up and immediately terminate)
versus if you run:
$ docker run -i node:slim
(the container will remain up after startup)
I hope that helps!
DevOps Directive Thank you! Awesome explanation!
Very helpful!! You are amazing!! very nice explanation! Thank you so much!! You fix my comprehension in just 6 minutes!! Can you make a tutorial with java ee wildfly postgres and angular please.
Thank you for the kind words!
I have minimal experience w/ Java and Angular, so I'm probably not the best person to make a tutorial like that.
@@DevOpsDirectiveOk. i understand.Thank you so much !!!
I want to use my mongodb atlas uri instead of mongo image How can i do so?
In this video I swap out the local DB for one running in atlas using an environment variable for the connection URI (ruclips.net/video/DftsReyhz2Q/видео.html)
I hope that helps!
If I'm using a .env with mongo db atlas uri what should I do?
Hi @Alberto! In this video I configure this app to use Atlas for the DB and use a .env file ruclips.net/video/DftsReyhz2Q/видео.html
Hopefully it helps!
@@DevOpsDirective thanks a lot!
I have a question.
What if i made some changes in express js or react js, do I need to type docker compose up again and the application will immediately change?
As configured in the video you would have to rebuild the image first. In my recent livestream (ruclips.net/video/DftsReyhz2Q/видео.html) I showed how to mount the source code into the container using a volume so that changes can be reflected immediately!
@@DevOpsDirective thankyou, will look forward for it
Good Content.
So lets say every part of the project runs in its own directory with different github repos.
Where exactly does the docker compose file go if there are multiple root directories? Does it go in the root of the front end or the backend?
I feel like not understanding something fundamental here.
Good question!
For the situation you described I would probably put the docker-compose file at the root of the backend repo and then use the git submodules (www.git-scm.com/book/en/v2/Git-Tools-Submodules) feature to make the frontend repo a sub directory within that repo.
If there are even more services (each as their own repo) you could even have a separate integration repo which has all the services as submodules.
My preference is just to use a single repo for everything ("Mono-repo") which simplifies your specific question, but adds its own complications elsewhere...
@@DevOpsDirective I was thinking of doing a Mono repos setup myself but wouldn't a large code base of a mono repo present
more stability, efficiency, and more importantly scalability challenges? The codebase will be large enough to more than likely suffer from one
or more of these issues.
"Git fundamentally never really looks at less than the whole repo. Even if you limit things a bit (ie check out just a portion, or have the history go back just a bit), git ends up still always caring about the whole thing, and carrying the knowledge around.
So git scales really badly if you force it to look at everything as one huge repository. I don't think that part is really fixable, although we can probably improve on it."
-Linus Torvalds
@Andrew -- how big a codebase are you working with? (in either SLOC or team size)
The majority of projects will never reach a scale where Git itself becomes the bottleneck.
For me, the benefits of being able to more quickly navigate and refactor across the codebase usually outweigh the (slightly) slower sync times or the need to configure CI/CD to be smart about detecting which services have been modified.
@@DevOpsDirective I'm not sure what the SLOC will be because the project is still in the early stages. I'm a few weeks into creating the api using TDD and my endpoint tests alone
are almost 5k lines of code.
Edit: The tests I have so far are only for about 15 endpoints. I still have at least 30 to go.
Hopeful that gives you an idea of the possible app scale.
@@fkw0k3t4rd5 Yeah, I doubt you would have issues with something of that scale.
I would choose whichever structure you are more comfortable with and will enable you to move the fastest during this initial development phase.
Great video! I'm learning docker and this was a great resource. Question though: Wouldn't the react-app depend on the api-server the same way the api-server depends on the mongo container?
Great question! You are correct that in order to successfully load the page with the movie results in your browser, the react app needs the API server to be running.
The difference is that those requests happen when you load the page not when you start the app! The react app is perfectly happy to start up independent of the other two services, whereas the API server will crash if it can't authenticate to the DB upon start up!
I hope that helps!
You had 440 subscribers, now you have almost 9 thousand. Congrats!
What if I need to specify username:password for images like Mongo/RabbitMQ?
Thanks @Levelord!
You would likely want to specify them as an environment variable. In this video, I show one method of doing this: ruclips.net/video/DftsReyhz2Q/видео.html
You can do this in the docker run command or with docker-compose (docs.docker.com/compose/environment-variables/#the-env_file-configuration-option)
My data is not displayed from database nor am I able to create new movies. It all worked before docker compose though . Can anyone help
RUclips comments are very cumbersome for technical discussions, but if you want to join the channel discord community someone can probably help! discord.gg/ExrENts5CT
❤️🔥
Hey man you are amazing , your explanation is clear and simple ,can you make a video on "how to deploy this application on GCP compute engine "
thankyou dear
Thanks @music! -- I have had a few people express interest in follow-ups to this video, so I will definitely make one! (not sure when though)
I am getting errors like this. Can you help me out?
Pulling mongo (mongo:)...
Traceback (most recent call last):
File "site-packages\docker\credentials\store.py", line 80, in _execute
File "subprocess.py", line 395, in check_output
File "subprocess.py", line 487, in run
subprocess.CalledProcessError: Command '['C:\\Program Files\\Docker\\Docker\
esources\\bin\\docker-credential-desktop.EXE', 'get']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\docker\auth.py", line 264, in _resolve_authconfig_credstore
File "site-packages\docker\credentials\store.py", line 35, in get
File "site-packages\docker\credentials\store.py", line 93, in _execute
docker.credentials.errors.StoreError: Credentials store docker-credential-desktop exited with "error getting credentials - err: exec: "docker-credential-wincred.exe": executable file not found in %PATH%, out: ``".
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 6, in
File "compose\cli\main.py", line 72, in main
File "compose\cli\main.py", line 128, in perform_command
File "compose\cli\main.py", line 1078, in up
File "compose\cli\main.py", line 1074, in up
File "compose\project.py", line 548, in up
File "compose\service.py", line 361, in ensure_image_exists
File "compose\service.py", line 1250, in pull
File "compose\progress_stream.py", line 102, in get_digest_from_pull
File "compose\service.py", line 1215, in _do_pull
File "site-packages\docker\api\image.py", line 396, in pull
File "site-packages\docker\auth.py", line 48, in get_config_header
File "site-packages\docker\auth.py", line 324, in resolve_authconfig
File "site-packages\docker\auth.py", line 235, in resolve_authconfig
File "site-packages\docker\auth.py", line 281, in _resolve_authconfig_credstore
docker.errors.DockerException: Credentials store error: StoreError('Credentials store docker-credential-desktop exited with "error getting credentials - err: exec: "docker-credential-wincred.exe": executable file not found in %PATH%, out: ``".')
[16672] Failed to execute script docker-compose
Hi Bharath --
Lets first confirm if your Docker Desktop install is working properly. What do you get if you test the docker version ("docker --version")?
Also, can you run "docker run hello-world" (which will pull and run hub.docker.com/_/hello-world)?
@@DevOpsDirective Hi there, thanks for response. I figured out the issue. I was running all commands from Git bash in windows instead of Windows command prompt which somehow caused something to go wrong.
But then, I ran into another error ( I have also posted it in stack overflow): stackoverflow.com/questions/63903112/mongo-connection-error-mongonetworkerror-failed-to-connect-to-server-localh
@@bharathram3977 It looks like the Stack Overflow question was removed... did you figure out the issue?
@@bharathram3977 FYI, I recently started a discord server to make discussions like this easier than YT comments. Come join if you want! discord.gg/CHRvYhwvej
I'm not sure how this stuff ends up working for people. I'm sure I'm doing something wrong, but it's always endless shots in the dark for me when it comes to Docker. I just want to get back to writing code :(
It is a fairly steep learning curve because of the additional abstraction, but once configured you shouldn't have to touch it much and hopefully will get teams writing code faster!
ty.
yw!
super easy
Awesome
Thanks @Md. Fazlul Karim!
awesome
Thanks @Ranga!
great
You can’t just run react app in webpack dev server and say this is your react docker container
whats the point any of this
I’m in shock. 50 y.o guy teaching the wrong stuff… this is the real problem. Why this even exist
Amazing video! You explained everything in a very understandable and clear way without oversimplyfing it. Love it