Is there a way to insert a dockerfile?

If the Docker file is written with errors, for example:

CMD ["service", "--config", "/etc/service.conf] (missing quote)

Is there any way to draw it in order to detect such an error before creating it?

+7
docker dockerfile
source share
4 answers

Try:

I performed a simple test against a simple Docker file with RUN , ADD , ENV and CMD . dockerlinter was wise to combine the same rule violation together, but it couldn’t check as thoroughly as hadolinter , possibly due to the lack of Shellcheck for static analysis of Bash code.

Although dockerlinter is out of scope, it can be much easier to install. npm install -g dockerlinter will do while compiling hadolinter requires a Haskell compiler and a build environment that compiles the compilation forever.

 $ hadolint ./api/Dockerfile L9 SC2046 Quote this to prevent word splitting. L11 SC2046 Quote this to prevent word splitting. L8 DL3020 Use COPY instead of ADD for files and folders L10 DL3020 Use COPY instead of ADD for files and folders L13 DL3020 Use COPY instead of ADD for files and folders L18 DL3020 Use COPY instead of ADD for files and folders L21 DL3020 Use COPY instead of ADD for files and folders L6 DL3008 Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>` L6 DL3009 Delete the apt-get lists after installing something L6 DL3015 Avoid additional packages by specifying `--no-install-recommends` $ dockerlint ./api/Dockerfile WARN: ADD instruction used instead of COPY on line 8, 10, 13, 18, 21 ERROR: ./api/Dockerfile failed. 
+8
source share

If you have a RedHat subscription, you can access the Linter for Dockerfile application directly at https://access.redhat.com/labs/linterfordockerfile/ ; application information is located at https://access.redhat.com/labsinfo/linterfordockerfile

This Node.js app is also available on GitHub https://github.com/redhataccess/dockerfile_lint if you prefer to run it locally.

+2
source share

I am not too familiar with go , but it looks like you can just call the Parse method, as is done in the test suite here . If this does not return an error, your lint will pass. I assume it is trivial to expose a script or something that needs to be called during development.

0
source share

I use dockerfile_lint in my CI pipeline very successfully. You can add or expand rules. Using package.json , you can create different configurations for different jobs. There are also

Docker CLI

 docker run -it --rm --privileged -v `pwd`:/root/ \ projectatomic/dockerfile-lint \ dockerfile_lint [-f Dockerfile] docker run -it --rm --privileged -v `pwd`:/root/ \ -v /var/run/docker.sock:/var/run/docker.sock \ projectatomic/dockerfile-lint \ dockerfile_lint image <imageid> 

and access to the Atomic CLI

  atomic run projectatomic/dockerfile-lint atomic run projectatomic/dockerfile-lint image <imageid> 

You can also draw your images for tagging.

0
source share

All Articles