fox
fox

Reputation: 16496

docker: installing a node.js application has issues, since docker runs as root

Set up a docker instance via pull ubuntu and then via base-image/docker, and then successfully installed node.js on top of this.

However, when I attempt to pull the repo of a node.js app that I'm working on, I get to an npm install action and then run into trouble because that action expects NOT to be run as root, and I have instantiated it via

docker run -name="{name}" -t -i {my custom docker container mirroring base-image) /bin/bash 

which has logged me in as root. Is there a way to run docker not as root?

Upvotes: 0

Views: 680

Answers (1)

Andy
Andy

Reputation: 38197

Yes -- you'll need to create the other user account inside the container according to whatever your container's Linux distro expects (here is an Ubuntu example).

Once you've got the user account set up, you can use the Dockerfile USER parameter to run the remaining commands in the Dockerfile as that user. Please see the PostgreSQL example for a full use case.

Where did the postgre user come from in that example? Debian packages create any users they need when they are installed. If you would like to create your own user you could add RUN useradd to your Dockerfile. For a full example, you could look at the Jira Dockerfile in this Atlassian Blog

As the operator you can also decide the user account to use at docker runtime, using the -u parameter. This would override the USER chosen in the Dockerfile.

Upvotes: 3

Related Questions