- As a user I want to complete this course without using my cloud or using the local version of the db.
The instructions here will both be imperative and declarative. It wont have any answers to the course. It will just be a collection of thoughts and deep dives into the code.
-
Understanding Docker as if it were a Game Boy - James Audretsch - Medium
-
If these two articles had a baby, this would be it.
- download mflix from the handouts
- unzip it. and go to that folder
- npm install
- Get the image
- docker pull mongo:4.04 or just pull the latest
- run the image with a few settings
-
docker run -d -p 27018:27017 / --name m220js / --v $(pwd)\input:\db\configdb / --v course-m220js-data:\db\data / mongo
-
-p <host_port>:<container_port> — map host port to container (publish)
- that means my computer's port (host) will transfer any requests over to 27017 on the container. I have mongodb installed and the default port is already taken over by 27017.
- -d means detached so you don't get weird logging and you can still use the terminal afterwards
- --v [lhs:rhs] (save the data so your container can go down but this memory card stays in place)
- left hand side is where it goes to. Either you name it like i did with course-m220js-data
- that gets stored inside
docker volume ls
- that gets stored inside
- specify a directory path in the lhs if you dont want docker to store the volume.
- \db\configdb are for storing info for sharded clusters
- \db\data are for database info itself
- left hand side is where it goes to. Either you name it like i did with course-m220js-data
-
-
mongorestore --gzip --uri --drop \ mongodb://localhost:27018 data
- load into our mongo database everything from the data folder using gzip. Since the folder inside of data is called mflix, your db name is also called mflix
- ---drop means drop any database called mflix if it finds it then mongorestore (load the data);
- confirm:
mongo mongodb://localhost:27018 show dbs; use mflix; show collections;
- load into our mongo database everything from the data folder using gzip. Since the folder inside of data is called mflix, your db name is also called mflix
- Go to your app's root directory
- the next step is to run the app's server
- checkout out what npm start does.
"start": "nodemon -L ./index.js",
- -L means that if i had mounted my app in a container, this -L shit will make it work.
- Now let's checkout index.js
- it has @babel/register · Babel which transpiles any es5 stuff on the fly.
- the exports export everything from the src file { all src stuff }. this is a little crazy that all functions are activated when you export them.
Notes:
When you stop a docker container from spinning, the volume is cached cuz docker is insane. Either do this or add the --rm
when you spin up the container.
Docker — Clean Up After Yourself! - Yohan Liyanage - Medium
It's also a good idea to remember that volumes persist if it has any data in them even if the --rm exists.