Friday, July 14, 2017

Dockerfile Linter --> projectatomic/dockerfile-lint


projectatomic/dockerfile-lint is one of a Dockerfile Linter which can parse and detect syntactical errors in Dockerfile

Usage

It can be called using Docker CLI as shown below

docker run -i --rm -v `pwd`:/root:ro projectatomic/dockerfile-lint dockerfile_lint

--------INFO---------

INFO: There is no 'EXPOSE' instruction. Without exposed ports how will the service of the container be accessed?. 
Reference -> https://docs.docker.com/engine/reference/builder/#expose


INFO: There is no 'CMD' instruction. None. 
Reference -> https://docs.docker.com/engine/reference/builder/#cmd
In the above command, I had a Docker file in my current directory and my current directory is mounted under /root inside the container. The above command created the container from the image projectatomic/dockerfile-lint and it ran the command dockerfile_lint from inside the container. The dockerfile_lint is a node script available in the PATH inside the container.

The above run gave 2 warnings that there is no "EXPOSE" and "CMD" instruction defined in the provided Dockerfile.

Here is an example of a Dockerfile with error

docker run -i --rm -v `pwd`:/root:ro projectatomic/dockerfile-lint dockerfile_lint
/opt/dockerfile_lint/lib/parser.js:454
            while ((isComment(lines[i].trim()) || !lines[i].trim())  && (i < lines.length)) {
                                      ^

TypeError: Cannot read property 'trim' of undefined
    at Object.parse (/opt/dockerfile_lint/lib/parser.js:454:39)
    at Linter.validate (/opt/dockerfile_lint/lib/linter.js:106:27)
    at lint (/opt/dockerfile_lint/bin/dockerfile_lint:85:33)
    at lintDockerFile (/opt/dockerfile_lint/bin/dockerfile_lint:104:9)
    at Object.<anonymous> (/opt/dockerfile_lint/bin/dockerfile_lint:144:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
Can you guess the issue in the Dockerfile which I provided by looking at the error?  Hell!!
I ended RUN command with "&&" , but I haven't provided next statement, as shown below

RUN apk --update add sudo python py-pip && \
    apk --update add build-dependencies python-dev && \
I hope this tool returns some better error message !!