Forbid npm update in Docker environment

3/18/2018

guys,

For various projects, I'm creating single Docker environments. Each Docker container consists of Debian, Nginx, Node.js, etc. and is going to use by developers as well as in production via Google Cloud's Kubernetes. Since the Node.js/module version should be everywhere the same, I would like to restrict the access to certain npm commands (somehow). Often developers work with different Node.js and project modules and that caused a lot of trouble in the past. With the Docker containers, I can provide environments with everything you need for a project. To finish this step, I would like to restrict the npm command execution and only allow arguments like install, test, etc.

Please drop me a comment if you know how to resolve this :)

Cheers

-- Bobby
docker
kubernetes
node.js
npm
shell

1 Answer

3/18/2018

It is almost impossible to limit your developers to run some commands in the container if they have an access to Dockerfiles and can somehow change a build flow.

But, because container providing isolation and you can build a custom container for which application based on your basic image, it can be not a big problem if the version of any package for one application will be changed somehow, as an example in a build step, because it will not affect other apps. They just have different containers.

So, you will not have a problem with compatibility like when you using one server with many application which using a shared environment.

The only one thing you need to do - make sure that nobody change container which you using as a base image.

-- Anton Kostenko
Source: StackOverflow