npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dockere

v0.6.0

Published

Create, build, and run a docker container with current-dir mounted as a volume

Downloads

14

Readme

dockere npm

…as in "dock here"

To quickly create a Docker container and mount current directory inside it.

C:\docker-test> dir /w/b
foo.js bar.css
C:\docker-test> dockere
Sending build context to Docker daemon
Step 1 : FROM ubuntu
Step 2 : WORKDIR /docker-test
Step 3 : CMD bash -li
Successfully built <id>
root@<id>:/docker-test# ls
foo.js bar.css
root@<id>:/docker-test# _

Install

npm i -g dockere

Usage


dockere [..options] [..non-options passed to docker run]

Options:
      --help             Show help
  -d, --dockerfile       Dockerfile to use.
                         Eg: alpine,nodejs,ubuntu,home,cwd
  -c, --command          Command to execute
  -v, --volume           Volume/mount points
                         <host>:<container>
  -h, --mountHome        Mount home directory
                         Short for --volume ~:/root
  -D, --mountDrives      <Experimental> Mount root drives in container's mount points /mnt/host/…
                         Short for --volume C:\:/mnt/host/c
  -n, --noMountCwd       Don't mount current directory. Mounts by default
      --passThrough, --  Pass through other options/args to docker run
  -b, --build            Force re-build image (docker build)
  -t, --tag              Tag to use for the image
      --workdir          Workdir to use [default: "/app"]
      --version          Show version number

Examples:
  dockere                  Run current-dir in a default (ubuntu) container
  dockere node             Run current-dir in a "node" container
  dockere -h               Mount the host's home-dir as container's ~/
  dockere -D               Mounts the hosts's root (C:|D:|…) drives in container's mount points /mnt/host/{c|d|…}
  dockere -v node_modules  Create a new volume '<workdir>/node_modules' in the container
  dockere -c echo hi       Execute a command and exit
  dockere -- -p 8080:8080  Expose the 8080 port by passing -p flag to docker run

Features

It:

  1. Creates a Dockerfile in current directory
  2. Builds an image from it
  3. Runs and attaches to it, while mounting current-dir as /<dir-name>

Dockerfiles

It comes with 3 basic template Dockerfiles: ubuntu [default], nodejs, and alpine.

On an empty dir, you can choose which one to load initially by

$ dockere -d ubuntu
Sending build context to Docker daemon
Step 1 : FROM ubuntu
...

This will create a Dockerfile in your current dir and your home-dir/.dockere for future use.

If there's already a Dockerfile in current dir and you specify a dockerfile template name, it will ask you whether you want to overwrite it with the default one.

$ dockere -d ubuntu
? Overwrite existing Dockerfile with "ubuntu" dockerfile template from Home? (y/N)

If there's already a Dockerfile in current dir and you specify a dockerfile template name that's not found in either your home-dir or this module provides, it will ask you whether you want to create a new template with this one and save it in your home-dir.

$ dockere -d custom
? Create a new "custom" dockerfile template from existing Dockerfile: (y/N)

It can save these, or any additional templates you create in your home-dir/.dockere

When saving in home-dir, it replaces all ocurrances of current-dir with template tag <workdir>, and vice-versa when loading from home-dir, so that you can use these in any other directory.

Command

The default command used is bash -li which lets you attach to the container. You can specify a different command:

$ dockere -c echo ok
...
Successfully built <id>
ok

Volume mounts

dockere offers some path improvements over Docker's default volume mount options.

Relative host-dir mount paths

Since Docker requires host-dir to be an absolute path, dockere lets you choose relative paths that can either be :

~/home paths

All paths beginning with ~ are adjusted with proper absolute path to your home-dir. Even for Windows users!

Eg.: You can mount your ~/.ssh for the container's root:

dockere -v ~/.ssh:/root/.ssh
Relative paths

Paths that don't begin with a / are adjusted to absolute paths relative to current-dir.

Eg.: You can mount a parent dir:

dockere -v ../parent:/parent

Relative container-dir volume paths

Again, since Docker requires container-dir to be an absolute path as well. dockere lets you choose relative paths that are adjusted to absolute path relative to your working-dir, which is the same name as your current-dir but inside the docker container.

** WARNING ** However this creates ambiguity as to what to do with a command like this:

dockere -v node_modules

The default Docker behaviour would have been to interpret this as a named volume, but dockere will treat it as a relative path and adjust it as a container-path relative to working-dir (Eg.: /app/node_modules in the container).

Use --named-volume instead to use named volumes. (todo: doesn't yet exist)

Mount home

You can mount your home-dir as /root

$ dockere -m # same as: dockere -v ~:/root
...
09:02 @MyBashPrompt /docker-test
$ cd ~/.ssh
09:02 @MyBashPrompt /root/.ssh
$ _

Troubleshooting

  • The mounted directory seems to be empty

    Make sure you've shared the relevant drive(s)

    Settings > Shared Drives