New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

docker-file-parser

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docker-file-parser

Parses a Dockerfile and returns an array of commands.

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7K
decreased by-13.82%
Maintainers
3
Weekly downloads
 
Created
Source

Docker file parser

Parses a dockerfile contents string and returns the array of commands, keeping the original file order.

Usage

var parser = require('docker-file-parser');
var options = { includeComments: false };
var contents = 'FROM ubuntu:latest\n'
            + 'ADD . /root\n'
            + 'RUN echo done\n';

var commands = parser.parse(contents, options);

commands.every(function (cmd) { console.log(cmd); });

Options

  • includeComments Whether to include comment commands in the returned array. A comment will have the command name as 'COMMENT'.

Command entries

Each returned command entry is an object with these properties:

  • name The capitalized name of the command, e.g. 'FROM'.
  • args Arguments for the command (can be array, string or map).
  • lineno Line number from the contents string.
  • error Only if there was an error parsing command.

Example:

{
    name: 'ADD',
    args: [ '.', '/srv/app' ],
    lineno: 5
}

Notes

There are other docker file parse modules for JavaScript, like dockerfile-parse and dockerfile-parser, this module differs in the follow aspects:

  • keeps the ordering of the commands (as they occur in the dockerfile)
  • written from a translation of the docker parser.go
  • properly handles character escaping and quoting, e.g. ENV myName="John Doe" myDog=Rex\ The\ Dog
  • handles multi-line commands (i.e. have a line continuance '' at the end)
  • can optionally include the comments

Keywords

FAQs

Package last updated on 11 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc