Socket
Socket
Sign inDemoInstall

docker-file-parser

Package Overview
Dependencies
0
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    docker-file-parser

Parses a Dockerfile and returns an array of commands.


Version published
Weekly downloads
6.9K
decreased by-27.35%
Maintainers
3
Install size
252 kB
Created
Weekly downloads
 

Readme

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

Last updated on 11 Jan 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc