Introduction
I have a demo Electron app which runs fine when running npm run start
from my Mac.
I'm interested in moving the application into a Docker container, but when docker-compose
reaches the electron
command step, I get the following:
...
> electron --no-sandbox .
/Users/presslertj/WebstormProjects/electron-frontend/node_modules/electron/dist/electron exited with signal SIGTRAP
electron_1 | npm ERR! code ELIFECYCLE
electron_1 | npm ERR! errno 1
electron_1 | npm ERR! electron-frontend@1.0.0 start: `electron --no-sandbox .`
electron_1 | npm ERR! Exit status 1
electron_1 | npm ERR!
electron_1 | npm ERR! Failed at the electron-frontend@1.0.0 start script.
electron_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
electron_1 |
electron_1 | npm ERR! A complete log of this run can be found in:
electron_1 | npm ERR! /home/electron/.npm/_logs/2021-03-12T21_35_03_623Z-debug.log
Files
/home/electron/.npm/_logs/2021-03-12T21_35_03_623Z-debug.log
:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'start' ]
2 info using npm@6.14.11
3 info using node@v14.16.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle electron-frontend@1.0.0~prestart: electron-frontend@1.0.0
6 info lifecycle electron-frontend@1.0.0~start: electron-frontend@1.0.0
7 verbose lifecycle electron-frontend@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle electron-frontend@1.0.0~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/presslertj/WebstormProjects/electron-frontend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle electron-frontend@1.0.0~start: CWD: /Users/presslertj/WebstormProjects/electron-frontend
10 silly lifecycle electron-frontend@1.0.0~start: Args: [ '-c', 'electron --no-sandbox .' ]
11 silly lifecycle electron-frontend@1.0.0~start: Returned: code: 1 signal: null
12 info lifecycle electron-frontend@1.0.0~start: Failed to exec start script
13 verbose stack Error: electron-frontend@1.0.0 start: `electron --no-sandbox .`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1048:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid electron-frontend@1.0.0
15 verbose cwd /Users/presslertj/WebstormProjects/electron-frontend
16 verbose Linux 4.19.121-linuxkit
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "start"
18 verbose node v14.16.0
19 verbose npm v6.14.11
20 error code ELIFECYCLE
21 error errno 1
22 error electron-frontend@1.0.0 start: `electron --no-sandbox .`
22 error Exit status 1
23 error Failed at the electron-frontend@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
docker-compose.yml
version: "3.9"
services:
electron:
image: docker-image-electron_v3:latest
user: electron
environment:
- DISPLAY=host.docker.internal:0
ports:
- "50051:50051"
volumes:
- "${PWD}:${PWD}"
- "/tmp/.X11-unix:/tmp/.X11-unix"
- "./docker-logs:/home/electron/.npm/_logs"
working_dir: ${PWD}
command: >
sh -c "
npm init -y &&
npm install &&
npm run start"
here's the Dockerfile
for docker-image-electron_v3
which is referenced in the docker-compose.yml
:
FROM centos:latest
RUN useradd -ms /bin/bash electron
RUN dnf install -y \
alsa-lib \
at-spi2-atk \
atk \
gdk-pixbuf2 \
gtk3 \
libdrm \
libxshmfence \
mesa-libgbm \
nss
RUN dnf module install -y nodejs:14
RUN mkdir -p /home/electron/.npm
RUN chown -R 1000:1000 "/home/electron/.npm"
Software Version Info
- electron = v12.0.1
- docker = 20.10.2
- docker-compose = 1.27.4
Questions
- What is causing the electron process to fail and how can I fix it?
- Is running electron from a container even a reasonable thing to do? To me it seems like an obvious and good idea but the fact that I am having a difficult way paving forward makes me very nervous