• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

How do I install dependencies using npm when MagicMirror is in a Docker?

Scheduled Pinned Locked Moved Troubleshooting
18 Posts 3 Posters 19.1k Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    smithbill17
    last edited by smithbill17 Jan 17, 2021, 10:40 AM Jan 17, 2021, 10:39 AM

    I’ve installed MagicMirror2 in a Docker container running on my Raspberry Pi 4b (alongside my Home Assistant setup also running in a docker container).

    MagicMirror (in docker) is running fine and I can add some modules to config.js no problem. However, i notice quite a few modules say to “install dependencies” using npm. I’m assuming ‘npm’ is something to do with node.js which is installed as part of the normal MagicMirror install process, but how can I use npm when my MagicMirror is in a docker container? When i try npm, it just gives me the expected ‘command not found’ error.

    Do i need to install the whole of node.js just to get npm working? Will this have a significant impact on my rpi4b? (I mainly use it for Home Assistant to control all my Smart Plugs, cameras etc., so don’t want to impact it too much by installing node.js if I don’t have to).

    S 1 Reply Last reply Jan 17, 2021, 11:23 AM Reply Quote 0
    • S Offline
      sdetweil @smithbill17
      last edited by Jan 17, 2021, 11:23 AM

      @smithbill17 there are two parts,

      node - the Javascript engine for outside the browser
      npm - the node package manager.

      npm is the library loader/version cross reference tool, loading libs from. nodejs.com

      so, u need to run npm from some command in the docker container to allow npm to connect to the online library repo and find and down load therequired libs

      the package.json file lists the libs (dependencies) each module has

      so maybe docker exec container npm…

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • K Offline
        karsten13
        last edited by Jan 17, 2021, 9:27 PM

        as @sdetweil already mentioned you have to run the npm install command from inside the container.

        If the container is running you can run docker ps to get a list of all running containers and so get the name of the mm-container.

        Assuming the container name is mm you can run docker exec -it mm bash which is the command to log in into the container. Now you have a bash from the container and can do all things from there.

        In your case you can navigate to the modules/MMM-XY folder and execute npm install.

        Running exit will leave the container.

        S 1 Reply Last reply Jan 17, 2021, 9:32 PM Reply Quote 0
        • S Offline
          sdetweil @karsten13
          last edited by Jan 17, 2021, 9:32 PM

          @karsten13 will leave the bash command running in the container. the container is still running

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • K Offline
            karsten13
            last edited by Jan 17, 2021, 9:39 PM

            @sdetweil not sure if I understand your question, with exit you leave the container but the container is still running.

            If you want stop the container there are several possibilities.

            If you used docker-compose up -d to start it you should use docker-compose down for stopping and removing.

            If you used docker run ... for starting you need the container name (e.g. mm) and then you can do docker stop mm for stopping and docker rm mm for removing (or docker rm -f mm for doing both in one statement).

            S 1 Reply Last reply Jan 17, 2021, 10:01 PM Reply Quote 0
            • S Offline
              sdetweil @karsten13
              last edited by sdetweil Jan 17, 2021, 11:53 PM Jan 17, 2021, 10:01 PM

              @karsten13 not a question, just adding words of understanding for non-docker aware users

              we have a ton of users doing /trying stuff with no systems expeience of any kind, no debug skills no system design info and im surprized how many make it part way thru.

              the things they are doing are pretty daunting for me w over 40 years.

              i spent about 8 months building a ci/cd virtual api test system w docker, in 2014. fell apart as the software we were using embedded the ip address of the other components in the data packets, instead of using nat

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • K Offline
                karsten13
                last edited by Jan 17, 2021, 10:14 PM

                First (forgot it in first respone): Get well soon!

                2014 is long ago concerning docker … It has advantages and disadvantages and I agree that users with minimal system experience should not use it.

                If you know what you are doing the main advantage is that you can test and run things without messing up your system. E.g. switch to another mm version is no problem, just use another container and you can test with the exactly same config and module setup. Or need another node version, just use another base image, …

                S 1 Reply Last reply Jan 17, 2021, 10:15 PM Reply Quote 0
                • S Offline
                  sdetweil @karsten13
                  last edited by Jan 17, 2021, 10:15 PM

                  @karsten13 if you know whay u are doing.

                  yes 2014 is light years ago.

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    smithbill17
                    last edited by smithbill17 Jan 18, 2021, 8:40 AM Jan 18, 2021, 8:33 AM

                    Firstly - apologies for the late reply. I had rather expected to get a “Someone replied to your posting…” email, but perhaps that setting isn’t ‘on’ in my forum profile (i’ll check).

                    Thank you everyone for the explanation and the details of how to use npm INSIDE the docker container. I did as @karsten13 had suggested (docker exec -it mm bash) and that seemed to work fine. I could run npm install inside the container. I then exited from that session and restarted my docker container.

                    However, i didn’t quite get working what I was attempting to do:

                    1. I have Home Assistant running on my rpi4b (in a docker container)
                    2. I have Magic Mirror2 also running (in a docker container) on the same rpi4b
                    3. I installed module Snille/MMM-homeassistant-sensors and its working fine
                    4. I wanted to use the MaterialDesignIcons as documented in Snille’s module - so I ran the ‘npm install’ command in the module directory inside the docker container as explained by @sdetweil and @karsten13 but, even after restarting my MagicMirror2 container, it made no difference to the icons.
                    5. I tried following the instructions in the alternative MMM-homeassistant-sensors by leinich by downloading the documented ‘master.zip’ of MaterialDesignIcons and unzipping that and running the ‘npm install’ command inside the docker container (and i tried inside the MaterialDesign-Webfont-master directory) but i still cant seem to use any of the icons in my Home Assistant sensor display.

                    Is there something obvious i’m doing wrong (or not doing)? Its not a big problem - i can live without the icons if necessary. I’m happy that I can display Home Assistant sensor data in MagicMirror2 as it is.

                    Perhaps i’m trying to install fonts in a docker container when in fact the fonts need to go in the relevant directories on the host? and without ‘npm’ being installed on the host, i can’t do that??

                    Would I be better ditching MagicMirror2 in a docker container, and instead install it natively on the host? (i was trying to keep my rpi4b as a clean host with HomeAssistant and MagicMirror2 neatly bundled into their own containers).

                    (incidentally, i do have 40+ years in IT, but just not in ‘hands-on’ stuff. I date from the days of FORTRAN, COBOL and Pascal - you’re probably all too young to even know what those were) :)

                    S 1 Reply Last reply Jan 18, 2021, 12:49 PM Reply Quote 0
                    • S Offline
                      sdetweil @smithbill17
                      last edited by Jan 18, 2021, 12:49 PM

                      @smithbill17 csn u tell us the instructions for adding the icons without docker?

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        1/18
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy