Developing Electron apps in MacOS using Docker

I’m here trying to write the article I wanted to find about this topic.

I’m not going to explain what Docker or Electron does, I’ll asume that you know what I’m talking about.

If you work in MacOS and want to develop Electron apps without installing a full NodeJS environment, you will find that it can be quite complicated specially because you’re not in a Linux environment where Docker runs natively.

Fortunately, now we have ‘Docker for Mac’ and thanks to XQuartz we can run desktop apps in MacOS by using a Docker container.
I want to show you how I did it, because it’s fairly likely that you spend some hours trying to find it out.

We’re gonna use nut, find out more about this project here:
https://github.com/matthieudelaro/nut

First of all, we need to install XQuartz which is an X server to be able to port some apps to MacOS, it’s possible that you need to restart the system in order make it work:

brew install xquartz

Because I know you don’t want to install weird stuff on your host, apart from xquartz, you won’t need to install anything else, the following downloads are very small and they just need to be placed in the root of your project, so you still have the control ;)

To get nut run this in the root of your project (it's a simple binary) and give it execution permissions:

curl -L https://goo.gl/sgJJtU -o nut && chmod a+x nut

Download thenut.yml in the root of your project, learn more about Nut in the github repository:

curl -L https://goo.gl/igLJ0p -o nut.yml

That’s it, finally you can run the container, and the UI will show up:

./nut run

Here’s an example with the Electron basic example:

Thanks for reading.

Software Developer ~

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store