Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron SIGSEGV Error When Running in Docker Container #41975

Open
jbanayo opened this issue Apr 26, 2024 · 2 comments
Open

Electron SIGSEGV Error When Running in Docker Container #41975

jbanayo opened this issue Apr 26, 2024 · 2 comments
Labels
blocked/need-info ❌ Cannot proceed without more information platform/macOS

Comments

@jbanayo
Copy link

jbanayo commented Apr 26, 2024

Issue Description:
I am trying to run an Electron application inside a Docker container, but I encounter the following error:

Electron Version: 13.6.9
Docker Version: 25.0.3
Operating System: MacOS

Questions:

What could be causing the SIGSEGV signal when running Electron in Docker?
How can I troubleshoot and resolve this issue to have Electron running successfully inside a Docker container?

> electron . --no-sandbox
/app/node_modules/electron/dist/electron exited with signal SIGSEGV

Expected Behavior:
I expect the Electron application to run successfully inside the Docker container, but it exits with a SIGSEGV signal.

Steps Taken:
I have used a Dockerfile based on a Debian stretch image to set up the necessary environment for Electron, including installing X11 libraries and other dependencies. Here is the Dockerfile I used:

Dockerfile


# Use a Debian-based image as the base image
FROM debian:stretch

# Set the ARG variables for user and Debian mirror
ARG user=electron
ARG debian_mirror=deb.debian.org

# Update the apt sources.list to use the specified Debian mirror
RUN sed -r -i -e s/deb.debian.org/$debian_mirror/ /etc/apt/sources.list \
    && apt-get update \
    && apt-get install -y --force-yes \
        build-essential \
        bzip2 \
        ca-certificates \
        curl \
        git \
        wget \
        python \
        vim \
        screen \
        net-tools \
        xvfb \
        fakeroot \
        gconf2 \
        gconf-service \
        gvfs-bin \
        libasound2 \
        libcap2 \
        libgconf-2-4 \
        libgtk2.0-0 \
        libnotify4 \
        libnss3 \
        libxkbfile1 \
        libxss1 \
        libxtst6 \
        libgl1-mesa-glx \
        libgl1-mesa-dri \
        xdg-utils \
    && useradd --create-home --shell /bin/bash $user

# Switch to the user we created
USER $user

# Set the working directory to the user's home directory
WORKDIR /home/$user

# Set the NVM and Node.js versions as ARG variables
ARG nvm_version=v0.34.0
ARG node_version=v10

# Install NVM (Node Version Manager) and Node.js
RUN wget -q -O /tmp/install.sh https://raw.githubusercontent.com/creationix/nvm/$nvm_version/install.sh \
    && . /tmp/install.sh \
    && export NVM_DIR="/home/$user/.nvm" \
    && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" \
    && nvm install $node_version \
    && npm install -g npm

# Install Electron globally
RUN npm install -g electron

# Switch back to the root user to copy the application files
USER root

# Copy the application directory into the container
COPY app /home/$user/app

# Set ownership of the application directory to the user we created
RUN chown $user.$user /home/$user/app -R

# Switch back to the user we created
USER $user

# Set the working directory to the application directory
WORKDIR /home/$user/app

# Install application dependencies
RUN npm install

# Set the default command to start the Electron application
CMD ["npm", "start"]
@codebytere
Copy link
Member

Could you please attach a crash dump to help us get more information? You can collect them by adding the following snippet to your main process code, before app.whenReady:

const { app, crashReporter } = require('electron')
console.log(app.getPath('crashDumps'))
crashReporter.start({ submitURL: '', uploadToServer: false })

Then reproduce the crash, zip up the crash dumps directory and attach it here.

@codebytere codebytere added platform/macOS blocked/need-info ❌ Cannot proceed without more information labels Apr 26, 2024
@jbanayo
Copy link
Author

jbanayo commented Apr 27, 2024

I was able to resolve the issue by following these steps:

Setting Up xvfb and Electron:

sudo apt-get update && sudo apt-get install -y xvfb
sudo apt-get install xvfb x11-apps x11-xkb-utils libx11-6 libx11-xcb1
sudo Xvfb :99 -ac -screen 0 1280x1024x16 &
export DISPLAY=:99
npm install --save-dev electron
sudo npm i -g electron-mocha

By this time, there is no more error with npm start however no window is appearing.

The solution for the window is

Configuring XQuartz on macOS:
To set up XQuartz for Docker and X11 forwarding on macOS:

  1. Launch XQuartz and enable TCP connections:
open -a XQuartz
defaults write org.macosforge.xquartz.X11 nolisten_tcp -boolean false

  1. Restart XQuartz for changes to take effect.
  2. Allow connections to the X server from Docker container:
    xhost +127.0.0.1
  3. Launch Docker container with appropriate display settings:
docker run --rm -e DISPLAY=host.docker.internal:0 \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  <your-container-image>

Inside the Docker container, test X11 forwarding with:
xeyes
If configured correctly, you should see the xeyes application window displayed on your macOS desktop. With that using npm start electron works!

I've tested this setup successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/need-info ❌ Cannot proceed without more information platform/macOS
Projects
None yet
Development

No branches or pull requests

2 participants