How do I create a distributable Docker image? - node.js

I'd like to build a NodeJS server packaged as an executable, which can then be installed and run on any Linux machine without any pre-requisite dependencies. I was considering packaging it as a Docker image, but that would mean that the user would need Docker to be installed on their system. Is there a way to package a Docker image itself as an executable, so that all the user needs to do is to run an executable file?

With docker NO
The answer for the executable from docker is no.
You can create docker/docker-compose project which you can simply run
if you have docker installed.
Without docker YES
But you can still package it without using docker (with the whole nodejs included in the executable).
Look at this link https://www.npmjs.com/package/pkg

Related

Install old packages in docker file

We are using docker containers as our build workspace . for compilation of our legacy code we need to use very old version of some of the Linux rpms. I tried giving the full name of the old rpm with their version , but it end up with the error package not available.
Request to please help how can i develop my docker file to install these old packages.
I have tried using alpine as well as centos image .
Please help me what is the correct way to do this as a good docker file practice.
One possible way is to download the package (with all the prerequisites), then in Dockerfile initiate the copy of package and additional file (if applicable) to the docker, then install them with rpm command.

How to to use Docker for ElectronJS app built in Windows?

I am working on a desktop application build using ElectronJS framework on Windows.
May be I haven't understood Docker properly, but how do I use docker for this app?
My end goal is to not let people install node, npm and electron packages on their local system. They can use the docker image to develop this application.
Update
I figured out how to package my project in docker image. Now I am struggling to run the app through the Docker Container.
How to run a GUI(Electron Application) application using docker container?
Thanks.
In your case you need custom docker images that will have node, npm and ElectronJS in it.
I found one such image on dockerhub, you can use it or build your own custom image by checking its dockerfile.

Building image from multiple docker hub images or private repo docker

i am able to create the dockerFile where i could do the stuffs. Its like i might have 10-15 apps running for now and more to go.
my dockerFile
FROM ubuntu:16.04
RUN installing necessary softwares
The thing i am trying is installing the softwares via images too. Like for
php7.0
FROM ubuntu:16.04
FROM php:7.0-cli
RUN installing necessary softwares
So currently i am making docker file for each project and do like FROM source RUN install this and that and same thing i have to do for the rest. Lets suppose i want to change the version of php for all 10 servers. i have to open file and edit. Any good suggestion to overcome this problem?
Maybe you can use ENV variables? Like
...
ENV PHP_VERSION=7.0
RUN apt-get install php=$PHP_VERSION
...
Or maybe use templating language which is offered by tool Rocker

Running nodejs serialport in a docker container

I need to run a nodejs application in a docker container. I'm not an expert in Linux so it's a bit hard to me to understand ho to do that. The whole application stored in github (https://github.com/kashesandr/NRTC). The app uses a serialport module (https://github.com/voodootikigod/node-serialport) that is compiled with node-gyp and in my case a serialport is a virtual one that uses a USB2Serial driver
(http://www.prolific.com.tw/US/ShowProduct.aspx?pcid=41)
I want to create a separate docker container for the app. Could you please help me?
This question is very vague.
There is an official image at docker hub for building node based images. There is plenty of "how to" info in the image's readme. The only tricky part seems to me is how to access the serial port from within the container. I believe it's only possible by running the container in privileged mode, while ensuring that the device node exists inside the container as well. Of course the USB2Serial driver need to be installed on the host operating system.
I'd suggest spin up the official node image in interactive mode, and try to install / run your app inside it manually, then you could figure out a script based on that later:
docker run -it --privileged -v /dev:/dev -v path-to-your-app:/usr/src/your-app node:4.4.0 /bin/bash
root#3dd71f11f02f:/# node --version
v4.4.0
root#3dd71f11f02f:/# npm --version
2.14.20
root#3dd71f11f02f:/# gcc --version
gcc (Debian 4.9.2-10) 4.9.2
As you see this would give you an interactive (-it) root access inside the container, which has everything you probably need, with an identical /dev structure as on the host os (-v /dev:/dev binds it), so there should be no problem accessing ports. (refine the -v /dev:/dev volume binding to something more specific later for security reasons). If you need everything else which is not installed by default, add it via apt-get (e.g. apt-get update && apt-get install [package]), as the official node image is based on Debian Jessie.
After you figured out how to run the app (npm install, gyp whatever), writing a Dockerfile should be trivial.
FROM node:4.4.0
RUN npm install ...\
&& steps\
&& to && be && executed && inside && the && image
CMD /your/app/start/script.sh
... and do a docker build, then run your image with --privileged, in non interactive (without -it) in production.

Boot a docker container from PXE

I would like to migrate an application server to a docker container. I currently have a PXE environment which i usually use to install new server and all necessary application and content.
Is there a way to get create a docker image that boots from PXE. After the install, them commit and save the image?
Thanks
If you can install a new server with the necessary application and content then you can certainly also install docker and your image. It would look something like this:
Install docker (client/server)
Use docker load to load your image from a tar file.
You can now do docker run on your image.
To save the image to a tar file use docker save.

Resources