docker-npm
docker-npm copied to clipboard
npm, yarn, node, npx, bower, grunt, gulp, generate-md - build and dev tools.
npm and related build and dev tools
Please feel free to create an issue or open a pull request if you need support or would like to contribute.
Portable node, package managers and build tools
- Tagged Images
- About
- Images
- Installation
- Change log
Announcements
v1.1.0 released
2019-02-25
- Added
nodev11 images and tests - Updated the shell scripts to default to
node-11-alpineimage (you can always use theDOCKER_NPM_TAGvariable to use another image).
Tagged Images
Images are tagged according to the installed Node version and operating system. Package versions are not pinned, instead npm is executed to install current versions of each package. If stability issues aries, I will pin package versions in a Dockerfile for that Node/OS version and create a image tagged as stable based on it. Please let me know if you run into this situation.
Alpine
alpine, latest Dockerfile
Based on node:alpine. This image should be considered under development and may not be as stable as versioned images.
node-11-alpine Dockerfile
Based on node:11-alpine.
node-10-alpine Dockerfile
Based on node:10-alpine.
node-9-alpine Dockerfile
Based on node:9-alpine.
node-8-alpine Dockerfile
Based on node:8-alpine.
node-7-alpine Dockerfile
Based on node:7-alpine.
node-6-alpine Dockerfile
Based on node:6-alpine.
Debian
debian Dockerfile
Based on node:latest. This image should be considered under development and may not be as stable as versioned images.
node-11-debian Dockerfile
Based on node:11-stretch.
node-10-debian Dockerfile
Based on node:10-wheezy.
node-9-debian Dockerfile
Based on node:9-wheezy.
node-8-debian Dockerfile
Based on node:8-wheezy.
node-7-debian Dockerfile
Based onnode:7-wheezy.
Other Images
node-7.7-alpine, 7.0-alpine Dockerfile
Based on
node:7.7-alpine, it node v7.7 compiled from source. The 7.0-alpine tagged version was accidentally upgraded over time to v7.7 and will remain so for the stability of existing users.
node-6.9-alpine, 6.9-alpine Dockerfile
Based on
alpine:3.4 with node v6.9 compiled from source.
node-7.0-debian, 7.0-debian Dockerfile
Based on
node:7.0-wheezy.
node-6.9-debian, 6.9-debian Dockerfile
Based on
node:6.9-wheezy.
About
Essentially, this is just a set of shell scripts that manage a Node.js docker image. The docker image includes a script (run-as-user) that allows commands to write files as either the current user or the owner/group of the current directory, which the shell scripts take advantage of to make sure files are created with your preferred permissions rather than root.
Images & Wrapper Scripts
The images contain the latest stable bower, generate-md, grunt, gulp, node, npm, npx, and yarn, binaries for node. When using the shell scripts available in the source repository, the current directory is mounted into /src inside the container and a wrapper script executes the specified command as a user who's uid and gid matches those properties on that directory. This way any output is written as the directory owner/group instead of root or a random user.
The included run-as-user script has three methods of determining which uid and gid to execute as:
-
By default, it will execute with a
uidandgidthat matches the current directory (the one that gets mounted into/src). -
In order to take advantage of public key authentication when installing packages from private repositories, all the wrapper scripts will attempt to mount your
~/.sshdirectory into the container. When that is successful, the script will run as theuidandgidof the owner of~/.ssh(you).Most software that takes advantage of public key authentication protocols do so over SSH, and by default, send the current user name as the login name. Because this process is executing out of a segregated container, it knows nothing about the current user's name and will instead try to login as a user named
dev. In order to work around this, you need to create a SSH configuration that specifies the correct username.In your
~/.sshfolder create a file calledconfig. In that file you need to specify the correct username. For example, to specify your login name for all hosts:Host * User mkenneyYou can easily be more explicit as well, specifying by host or with additional wildcards. Google is your friend.
Host github.com User mkenney -
You can also explicitly specify the
uidandgidto use at runtime by defining thePUIDandPGIDenvironment variables when executing the container, this is quite useful in automated build systems:docker run \ --rm \ -it \ -v $(pwd):/src:rw \ -e "PUID=<user id>" \ -e "PGID=<group id>" \ mkenney/npm:latest <commands>
The included wrapper scripts default to the latest node version and image tag I feel is stable, I will update the default tag as updates are released or stability issues warrant (node-10-alpine at the moment).
To specify a different image, you can define the image tag in your environment which will set a new default (you probably want to define this in your .bashrc or similar profile script):
export DOCKER_NPM_TAG=node-6.9-alpine
or you can easily specify it at runtime whenever necessary, for example:
$ DOCKER_NPM_TAG=node-6.9-alpine bower install
If you would to see like additional node modules and/or wrapper scripts added to this project please feel free to create an issue or open a pull request.
Installation
This assumes that you already have Docker installed. A running docker daemon is required. You probably want to be able to run docker commands without sudo, but even if you excute the scripts with sudo files will be written with the appropriate uid and gid.
Wrapper scripts for several commands are available in the source repository:
Installation is just a matter of putting them somewhere in your path and making them executable. An installation script is available and can be executed with a shell curl+sh -s command. Simply pass in your command arguments normally.
Usage
install.sh COMMAND [TAG [PREFIX]]
Synopsys
Install a mkenney/npm container execution script locally
Options
COMMAND - Required, the name of the command to install (bower, gulp, npm, etc.)
TAG - Optional, the image tag to use. Default 'latest'
PREFIX - Optional, the location to install the command script. Default '$HOME/bin'
Examples
$ curl -L https://raw.githubusercontent.com/mkenney/docker-npm/master/bin/install.sh | bash -s gulp node-10-alpine $HOME/bin
$ bash ./install.sh gulp node-10-alpine $HOME/bin
Updating
-
[command] self-updateEach of the scripts have a
self-updatecommand which pulls down the latest docker image (which all the scripts share) and then updates the shell script itself. If you don't have write permissions on the shell script you'll get a permissions error, you can run the self-update command withsudoif necessary.