Build An Audio AI App Transcripts
Chapter: Tour of Starter App
Lecture: Running MongoDB (in Docker)

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that we've got our virtual environment set, you can see, move out of the way here for a second, you see PyCharm down here says
0:07 it's using this virtual environment, which is excellent. The final thing to do is to set up MongoDB on our server. And again, here are the steps.
0:18 So let's go back to our terminal here. It doesn't matter where on your computer you do this. So we'll say docker pull mongo,
0:27 and that'll get the latest MongoDB. It says, look, you've already got it because guess what, I've done this before.
0:33 It actually just updated a couple hours ago. Then the next thing we're gonna do is say docker volume create.
0:41 I'm gonna say docker volume create MongoDB, and I'm not going to actually run this because I already have this volume,
0:50 but run this, it'll say created a volume. Again, the point of this is here's a persistent bit of storage. So when Docker restarts or whatever,
0:59 the container goes away, you upgrade it or something along those lines, this persists. Otherwise the database files backing in Mongo
1:08 will go away every time you restart your container. Not great for a thing that's supposed to be a persistent data storage, right?
1:15 And then finally, I'm gonna go down here to the command so I can copy it, paste it in here. We're gonna say docker run, don't block,
1:24 and just run it in the background as long as I'm logged in until I do something in a mode that if I stop it, it cleans up after itself
1:32 so that it listens on localhost to this port and forwards it inside the container. So just forwards on all traffic using this new volume
1:40 we just created, mapping that to data/db and give it a stable name so we can refer to it running this image that we just got. So let's go and run that.
1:55 And look at that, it's up and running and now we can say docker ps, you can see it's sitting here running and its name is, if I zoom out,
2:02 its name is a Mongo server. It's just gonna always be named that, perfect. So pretty much you don't ever have to do anything again
2:09 unless you reboot your computer or for some reason stop Docker. But if you don't do those things,
2:14 just close this and you have a database server running. All right, excellent. So now our settings here, our MongoDB installed
2:24 and it's incredibly lightweight and easy to get rid of. Told you about Orbstack, we can go down here, you can see that it's running.
2:31 If you go to the volumes, you can see there's Mongo data. I've actually loaded some other data into it for other apps that I have going
2:39 and some other things just hanging around. These are unused, we can clean them up if we wish, like so. All right, so you can monitor
2:48 what's going on with all these things, but you don't need to, just in case you're curious. Finally, I want to run this code
2:55 so I can right click on main and say run. Excellent, see this stuff came from the database. That's 'cause I ran it before.
3:05 You guys will see importing these various podcasts and then the next time you run it, you'll see this. So we're talking to our local MongoDB
3:16 and everything looks like it was great there and yeah, the app is running. Let's just click this and see what we get.
3:23 Here it is, yes, the app is up and running. I'll give you a tour around the app next.

Talk Python's Mastodon Michael Kennedy's Mastodon