Exploring Docker [2] - Docker Compose With Node & MongoDB



In this video we will take a simple Node/Express/Mongo app and dockerize it by adding a Dockerfile and using docker-compose to bundle services together. We will also run our containers on a Digital Ocean droplet.

Sponsor:
DevMountain Bootcamp – https://goo.gl/6q0dEa

Code For This Project:
https://github.com/bradtraversy/docker-node-mongo

$10 off Digital Ocean
https://m.do.co/c/5424d440c63a

Docker Help Gist:
https://gist.github.com/bradtraversy/89fad226dc058a41b596d586022a9bd3

💖 Become a Patron: Show support & get perks!
http://www.patreon.com/traversymedia

Website & Udemy Courses
http://www.traversymedia.com

Follow Traversy Media:
https://www.facebook.com/traversymedia

https://www.instagram.com/traversymedia

source

45 thoughts on “Exploring Docker [2] – Docker Compose With Node & MongoDB”
  1. If you want your data to persist in prod, add something like this to your mongo service…

    volumes:
    – ./data/db:/data/db

    .There are many resources online so when you create these files, be sure to check some other examples. This is a very basic setup

  2. Hi Brad, this whole series is really awesome. I have one question about mongo container. Do we need container for mongo if we are using mongo atlas service ?

  3. so a password and user was not set on the MongoDB image? What would be the enviromnents for the docker-compose.yml file to add this?

  4. Dude you just saved me like a full days worth of headaches thank you, awesome video! How would you turn that IP from digital ocean into a domain name?

  5. Why are you using node_modules from the host machine? It should be from the container since some binaries may differ based on the host machine. BIg fan btw

  6. You can just run `git checkout 3ad2b18` to get the state of the repo shown at the beginning of the video

  7. i am getting an error: Not able to connect to mongodb after running command docker-compose. Can someone pls help

  8. Thanks a bunch! Great tutorial, and nice that you left the ssh key part etc. in the final edit, makes me feel normal 😀

  9. A little beyond this intro, but is is possible to drop an "existing" WordPress site into a Docker environment like this? If so, does anyone have any online guides that talk about that? I need the database from an already existing WordPress site, to be within this new Docker area, along with the exported theme package.

  10. Hi, I'm having some trouble finding information on how to actually connect to the container from the app, i.e. not using mongo shell.

    Could anyone point me to resources explaining this ?

    Thanks,
    Nuno

  11. Question:
    Do I have to build image and docker-compose every time files are modified when developing the project?
    I have no experience of development using Docker.

  12. Again, – Brad to the Rescue. Just started working with Docker-Compose and besides it not doing what I wanted- it kept installing packages with yarn :X glad this video was around to save my day… again.

  13. I’m glad you didn’t edit out your fumbling with the SSH keys and passwords, it was the most relatable part of the video 😂😭

  14. Genuinely love this walkthrough, but my favorite moments are: whispering "shit" and the 4 attempts to login.

  15. 1:20❤️GitHub.com/traversy/docker-node-mongo
    node installed
    1:45🔴package.json
    2:15❤️index.js
    3:25❤️views/index.ejs
    3:40❤️ Dockerfile
    FROM node:10
    WORKDIR use/Src/app
    COPY package.json ./
    RUM npm install
    COPY . .
    EXPOSE 3000
    CMD ["npm", " start"]
    8:40❤️ docker-compose.yml
    version: '3'
    services:
    app:
    container_name: docker-node-mongo
    restart: always
    build: .
    ports:
    -'80:3000'
    links:
    -mongo
    mongo:
    container_name: mongo
    image: mongo
    ports:
    -'27017:27017'
    12:00❤️ dockerignore
    node_modules
    npm-debug.log
    12:50terminal,docker-compose up
    14:00
    localhost
    14:50ctrl+c
    15:00docker-compose down
    16:10❤️
    git add .
    git commit -m 'Added Docker to app'
    git push
    17:00❤️ digitalocean.com
    18:30❤️ localhost,imac
    cat ~/.ssh
    ls ~/.ssh
    cat ~/.SSH/id_rsa_do.pub
    Copy and paste into digitalocean
    20:25❤️ssh root@digitalocean server ip
    Denied❤️❤️❤️❤️❤️❤️
    ssh-add ~./.ssh/id_rsa_do
    Identify added: /users/bradtraversy/ .ssh/id_rsa_do (/users/bradtraversy/.ssh/id_rsa_do
    ssh root@digitalocean server ip
    21:30❤️git clone git@githun.com/: bradtraversy/docker-node-mongo.git
    ls
    ssh-keygen
    cat ~/.ssh/id_rsa.pub
    Copy and paste into github.com,settings, SSH and gpg keys23:30
    git clone git@githun.com/: bradtraversy/docker-node-mongo.git
    ls
    docker-node-mongo
    23:40❤️cd docker-node-mongo
    ls
    docker-compose up

  16. I think you could have gone with git clone on the server to pull the repo instead of ssh. That wouldn't have required a key or password. Great video as always. Thank you for sharing.

  17. why do we need to COPY package*.json first? the next line COPY . . copies everything including the package.json files to the container, or am I wrong?

  18. Would love to see some more docker stuff. A tutorial with react/express/mongo + docker would be awesome. Maybe even some Kubernetes at some point!

  19. Hi, quick question: How about I use nodmon and MySQL as a database, I am not using express in the package.json. Should I add express on it before dockerizing? btw my index.js is placing in the directory, should I create the dockerfile and docker-compose on that directory or I can just create in the node root folder?

  20. Starting v3, the Link is implicit and is no longer required. When containers are placed in the same network, they are reachable by each other using their container name and other alias as host.

Leave a Reply

Your email address will not be published.

Captcha loading...