Coder Social home page Coder Social logo

docker-node's Introduction

Docker + node template

Requirements

  • Docker

Get started

To allow for autocompletes, eslint, etc during development.

  • cd app1
  • npm ci
  • cd ..
  • docker-compose build && docker-compose up

This will fire up MongoDB, Mongo Express, a simple node app with some sockets and database connection, and one hello world node app.

Docker stack

To run the entire stack as a... stack within a orchestrator such as Docker Swarm.

  • docker stack deploy -c docker-compose.yml -c docker-compose.prod.yml vikingtomrulez

Questions to myself while testing node_modules and docker

  • Question 1: If all dependencies are installed within the containers themselves. As a host of the containers and as developer with an IDE, how do I get autocomplete when none of the dependencies are on the host?

    • Conclusion: We need to synchronize host machine repo, with the container's directory through Docker volumes. Not recommended. Just install packages on host instead.
  • Question 2: If developers install dependencies on the host machine, and Docker expects to install dependencies and also copy the application over to its containers, the host dependencies will be copied. Which dependencies are the correct ones?

    • Conclusion: Exclude node_modules from being mounted on volumes?
  • Question 3: If project A installs dependencies, and project B requires the same dependencies, can project B use project A's dependencies?

    • Conclusion: Mount project a into a shared volume. Then use volume_from on project A (Recommended with read only rights). However, it is quite unlikely that project B creates an image that depends entirely on other images (project A). So this entire scenario isn't very recommended.
  • Question 4: Hot module reloading for frontend devs. Since all the packages will be on the container, and we're running libraries such as webpack from the container, will the libraries notice changes in code on the host and reload the app?

    • Conclusion: Don't run frontend apps through containers during development. It IS possible to watch for changes in the container files, then map it etc, but it is a hassle. Not recommended. Do it the other way around, run packages on host, then mount into container.
  • Question 5: In our Dockerfiles: Why separately copy package*.json into the container, install packages, THEN copy the rest of the app?

    • Conclusion: A Docker image consists of multiple layers. Docker will detect changes in each layer. If we copied and installed everything in one layer, and did a change in our source code, we would have to install all of the node packages for each build. By separating it into different layers, packages will only be installed if there are changes within the layer that has to do with packages.

Troubleshooting

  • Nodemon doesn't detect changes on host.
    • Make sure host mounts source code into container.
    • nodemon -L worked for me. This will enable legacy chokidar snacks.
There are several approaches on how to deal with node_modules and docker.

docker-node's People

Contributors

vikingtristan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.