Skip to content

Instantly share code, notes, and snippets.

@austinfrey
Last active January 21, 2017 21:18
Show Gist options
  • Save austinfrey/ee3247c2afbd919622cb7d61550856fe to your computer and use it in GitHub Desktop.
Save austinfrey/ee3247c2afbd919622cb7d61550856fe to your computer and use it in GitHub Desktop.
Making a stripped down node.js docker image

Create a directory to house your assets

mkdir hello-world && cd hello-world
touch Dockerfile

Let's install the npm package that will bundle our application into a standalone exectuable. This might take a few minutes.

npm install -g enclose

For our node.js server the contents of the Dockerfile would look like the following.

FROM resin/rpi-raspbian

ADD helloworld helloworld

RUN chmod u+x helloworld

...and our helloworld.js file...

echo "console.log('hello world');" >> helloworld.js

Now to bundle it all up!

enclose -o helloworld ./helloworld.js

Now we can build our image...

docker build -t hello-world .

From here we will use a bash script to strip the image of everything but the helloworld executable

cd
git clone https://github.com/mvanholsteijn/strip-docker-image.git
cd strip-docker-image/bin
strip-docker-image -i hello-world -t mini-hello-world -f helloworld

That should leave us a much smaller image containing only the helloworld We can run it with...

docker run mini-hello-world ./helloworld

You should see hello world printto your terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment