I’m trying to create a Node.js based docker image. For that, I’m looking for options for Parent image. Security is one of the main considerations in the image and we wanted to harden the image by not allowing shell or bash in the container.
Google Distroless does provide this option, but Distroless-NodeJS is in the experimental stage and not recommended for production.
Possible options I could think of are (compromising Distroless feature):
- Official Node Image (https://hub.docker.com/_/node/) / Alpine / CentOS based image (but all would have a shell I believe).
With that being said,
-
Is there any alternative for Distroless?
-
What are the best options for the parent image for Node.js based docker image?
Any pointers would be helpful.
3
Answers
One option would be to start with a Node image that meets your requirements, then delete anything that you don’t want (sh, bash, etc.)
At the extreme end you could add the following to your Dockerfile:
Although I am not certain that this wouldn’t interfere with the running of node.
On the official Node image (excl Apline) you have
/bin/bash
,/bin/dash
and/bin/sh
(a symlink to/bin/dash
). Just deleting these 3 flies would be sufficient to prevent shell access.The Alpine version has a symlink
/bin/sh -> /bin/busybox
. You could delete this symlink, but it may not run without busybox.I think you can build an image from scratch which only contains your node application and required dependency, nothing more even no
ls or pwd
etc.scratch-node
So if someone tries to get the shell,like,
Will get error
I am referring this from official Node.js docker image.
Create a docker file in your project.
Then build and run docker image:
If you prefer docker compose:
Run the compose file: