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

docker-hub-tags

v1.0.1

Published

NodeJS lib, with which you can easily find the latest version of Docker Hub images

Downloads

7,064

Readme

DEV pipeline

Docker-Hub-Tags

NodeJS lib, with which you can easily find the latest version of Docker Hub images.

I also publish my own applications in docker images and use Docker HUB for this. Several times I ran into the fact that many or very many images are published, it is difficult to find if there is a more recent version. And the names of the images and tags are also quite varied, it is difficult to navigate them.

If you want to access the list of images of a Docker Repository from a NodeJS application and search it with semantic versioning, then you have found the solution: npm, TypeScript, well tested!

Install

# install package from npmjs
npm i docker-hub-tags

Usage

The very first step is to download the Docker Hub repository information. You can initialize the DockerHubTags class with this. After that, you can perform one or more actions or searches without internet traffic.

  • Access the repositories belonging to the (community) user namespace (eg: adobeapiplatform/apigateway, openebs/mayastor-casperf, etc.)
  • Access the Official Images (eg: Node, Nginx, Ubuntu, Python, Redis, Mysql, etc.)
# namespace in community
const dht = await DockerHubTags.init('adobeapiplatform', 'apigateway');

# official image category
const dht = await DockerHubTags.init(OFFICIALIMAGES_NAMESPACE, 'node');

Filter and limit

You have the option to filter the images if you are only interested in the images of one platform. You can limit the amount of downloaded data for performance reasons. (By default it downloads 1000 tags, this requires 10 steps/page, usually enough)

const dht = await DockerHubTags.init(
    OFFICIALIMAGES_NAMESPACE,
    'node',
    # retrieve linux/arm64 images only
    {
        os: 'linux',
        architecture: 'arm64'
    },
    # fetch 300 taginfos only
    { limit: 300 }
);

Cache

You can easily save the data you have already downloaded so that you can load it again later. You can create a storage service that caches the data for a day, for example.

const dht = await DockerHubTags.init(OFFICIALIMAGES_NAMESPACE, 'node');
const savedData = dht.exportToJson();

# Later...
const dhtFromFile = DockerHubTags.createFromJson(savedData);

Query

The most important part is that you can extract detailed information about the members. All tag information contains the tag, its images and other tags equal to the tag (sameTags: current-bookworm = 21.5.0-bookworm)

const dht = await DockerHubTags.init(OFFICIALIMAGES_NAMESPACE, 'node');

# One tag
dht.getTag('20.10-bookworm');

# Latest tag (if exists)
dht.getLatest();

# All tags
dht.getAllTags();

Query for recent version

Based on the member information, you can easily find out whether there is a newer version for the current version. You can use the rules of semantic versioning. We have added a special rule to the set. An exclamation mark (!) indicates that it will provide a parity version.

const dht = await DockerHubTags.init(OFFICIALIMAGES_NAMESPACE, 'node');

# patch version (~20.0.5 -> 20.0.11)
dht.getRecent('~20.0');

# minor version (^20.0 -> 20.11)
dht.getRecent('^20.0');

# major version (^20.0 -> 21.9)
dht.getRecent('20.0');

# majorParity version (!18.0 -> 20.10)
dht.getRecent('!18.0');

# majorParity version (!19.0 -> 21.5)
dht.getRecent('!19.0');

# postfixed version (20.1-bookworm-slim -> 21.9-bookworm-slim)
dht.getRecent('20.1-bookworm-slim');

This is the general structure of a result set. You can easily extract the necessary information from it.

{
  name: 'latest',
  tag_status: 'active',
  content_type: 'image',
  full_size: 400342209,
  last_updated: 2023-12-20T22:00:44.304Z,
  digest: 'sha256:73a9c498369c6....',
  images: [
	{
	  os: 'linux',
	  architecture: 'arm64',
	  variant: 'v8',
	  size: 390989031,
	  status: 'active',
	  digest: 'sha256:4fe798298b45cdc8ebfb3....'
	}
  ],
  sameTags: [
	'latest',
	'current-bookworm',
	'current',
	'bookworm',
	'21.5.0-bookworm',
	'21.5.0',
	'21.5-bookworm',
	'21.5',
	'21-bookworm',
	'21'
  ]
}

More examples

Explore the examples folder for more examples.