(Solved) Creating a DockerFile for Magic Mirror Server?

For over an hour, I’ve been struggling to create a MagicMirror Server instance using DockerCompose. The closest I’ve gotten has been to run

docker run -d --publish 9447:8080 --restart always --volume ~/magic_mirror/config:/opt/magic_mirror/config --volume ~/magic_mirror/modules:/opt/magic_mirror/modules --volume /etc/localtime:/etc/localtime:ro --name MagicMirror bastilimbach/docker-magicmirror

The problem with the above is that DockerImage had been last updated 3 years ago so I assume it’s not running MagicMirror v.2.27.0 (latest release).


It appears that this DockerImage is an official image, however when I run the following DockerCompose

version: ‘3.3’
services:
magicmirror:
container_name: MagicMirror
image: karsten13/magicmirror:v2.27.0
restart: always
ports:
- “9445:8080”
volumes:
- /etc/localtime:/etc/localtime:ro
- ~/magic_mirror/config:/opt/magic_mirror/config
- ~/magic_mirror/modules:/opt/magic_mirror/modules
networks:
- magicmirror_net

volumes:
magicmirror_data:
name: magicmirror_vol

networks:
magicmirror_net:
driver: bridge

The DockerCompose runs but the container endlessly restarts with the error

sh: 1: ./node_modules/.bin/electron: not found

which seems to be because Electron is not installed in the karsten13 DockerFile.


It seems like my only option at this point is to create my own DockerFile, possibly based around one of these DockerFiles, which I assume are official?

Help?

Hmmm,

It’s not that Electron isn’t installed on the container but that the node modules aren’t downloaded to the container properly.

Or maybe the reference isn’t there. I’d definitely rip the dockerfile you linked and try to get it working. Strongly recommend using the alpine one.

I’m happy to help, but you’ll have to ask some more pointed questions, I’m not entirely sure where you need guidance.

1 Like

This ended up being the problem. There’s actually multiple different types of images available for Docker MagicMirror and I guess the one I was choosing was the wrong one.

I ended up coming up with this DockerCompose, which seems to work but is slightly-different from the multiple different DockerCompose files that I’ve seen.

version: ‘3.3’
services:
magicmirror:
container_name: MagicMirror
image: karsten13/magicmirror:latest
restart: always
ports:
- “9445:8080”
volumes:
- magicmirror_data:/opt/magic_mirror/config
- magicmirror_data:/opt/magic_mirror/modules
- magicmirror_data:/opt/magic_mirror/css
command:
- npm
- run
- server
networks:
- magicmirror_net

volumes:
magicmirror_data:
name: magicmirror_vol

networks:
magicmirror_net:
driver: bridge

Specifically the
"
volumes:
- magicmirror_data:/opt/magic_mirror/config
- magicmirror_data:/opt/magic_mirror/modules
- magicmirror_data:/opt/magic_mirror/css
"
is different from what I saw here but it seems to work? I’ll need to see whether all of the data is actually being safely kept in the volumes.

I also pulled this part from the same serveronly.yml file, which I added.

command:
- npm
- run
- server

Solved I guess?

2 Likes

Replying here as I just went through trying to look for how to run Magicmirror in docker in server mode and it was confusing AF.

here’s a basic docker-compose.yaml that is working for me.

services:
  magicmirror:
    container_name: magicmirror
    image: karsten13/magicmirror:latest
    restart: unless-stopped
    volumes:
      - (your/local/folder/here/)magicmirror/config:/opt/magic_mirror/config
      - (your/local/folder/here/)magicmirror/modules:/opt/magic_mirror/modules
      - (your/local/folder/here/)magicmirror/css:/opt/magic_mirror/css
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env

Then needed to create an .env file
I commented out a lot of stuff that was in there… the important one is that it specifies server mode. read the env notes to see if they apply to your setup

# Possible values: "server" or "electron" or "client":
MM_SCENARIO="server"

# You can disable the init container (which corrects volume permissions) by changing MM_INIT to "no".
# You must specify "no" when using scenario "client".
# In most usecases you need to run the init container on first start and can then disable it.
# possible values: "init" or "no":
MM_INIT="init"
# Permissions used in init container:
MM_UID="1000"
MM_GID="1000"
MM_CHMOD="777"

# Docker Image to use:
MM_IMAGE="karsten13/magicmirror:latest"

# Port mapping used for scenario "server":
MM_SERVER_PORTS="8080:8080"

# Volume Mounts
#MM_MODULES_DIR="modules"
#MM_MODULES_DIR="config"
#MM_CSS_DIR="css"
#MM_CSS_DIR="config"
#MM_CUSTOMCSS_FILE=${MM_CSS_DIR}/custom.css

#VOLUME_CONFIG="../../mounts/config:/opt/magic_mirror/config"
#VOLUME_MODULES="../../mounts/${MM_MODULES_DIR}:/opt/magic_mirror/${MM_MODULES_DIR}"
#VOLUME_CSS="../../mounts/${MM_CSS_DIR}:/opt/magic_mirror/${MM_CSS_DIR}"

# Port and ip address used for scenario "client":
#MM_CLIENT_PORT="8080"
#MM_CLIENT_ADDRESS="192.168.0.1"

# If you want to use https://github.com/Bee-Mar/mmpm you can add
# the mmpm container to this setup by changing MM_MMPM to "mmpm".
# Possible values: "mmpm" or "no":
#MM_MMPM="no"

# If you need to use a xserver e.g. on distribution without gui
# Possible values: "xserver" or "no":
MM_XSERVER="xserver"
# Use following params to set orientation, scaling, port of the xserver,
# example for XRANDR_PARAMS="--output HDMI-1 --rotate left --scale 1.9"
#XRANDR_PARAMS=""
# Time to wait for the xserver to start before executing xrandr command
#XRANDR_DELAY="5s"

# For the following parameters see https://khassel.gitlab.io/magicmirror/configuration/
MM_OVERRIDE_DEFAULT_MODULES="true"
MM_OVERRIDE_CSS="true"
MM_SHOW_CURSOR="false"

# set the project name (see https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name):
COMPOSE_PROJECT_NAME=magicmirror

# Watchtower Setup
# Possible values: "watchtower" or "no":
#MM_WATCHTOWER="no"
# Interval in seconds checking for new images:
#MM_WATCHTOWER_INTERVAL=300
# if set to "--cleanup" old images are deleted, otherwise set to "":
#MM_WATCHTOWER_CLEANUP="--cleanup"

Finally, I changed ownership of the folder to that userid

docker logs show it’s running 2.29.0 server and no errors :+1: