Hadolint提升Dockerfile的质量和安全性 —— 筑梦之路

https://github.com/hadolint/hadolint

hadolint 在线版本:https://hadolint.github.io/hadolint/

bash 复制代码
FROM debian
RUN export node_version="0.10" \
&& apt-get update && apt-get -y install nodejs="$node_verion"
COPY package.json usr/src/app
RUN cd /usr/src/app \
&& npm install node-static

EXPOSE 80000
CMD ["npm", "start"]
bash 复制代码
nerdctl run --rm -i hadolint/hadolint < Dockerfile

-:1 DL3006 warning: Always tag the version of an image explicitly
-:2 DL3015 info: Avoid additional packages by specifying `--no-install-recommends`
-:2 DL3009 info: Delete the apt-get lists after installing something
-:2 SC2154 warning: node_verion is referenced but not assigned (did you mean 'node_version'?).
-:4 DL3045 warning: `COPY` to a relative destination without `WORKDIR` set.
-:5 DL3003 warning: Use WORKDIR to switch to a directory
-:5 DL3016 warning: Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`
-:8 DL3011 error: Valid UNIX ports range from 0 to 65535

指定忽略的规则

如何你想忽略某些规则,在项目目录下创建hadolint.yaml文件,并指定要忽略的规则

bash 复制代码
ignored:
  - DL3011

运行Hadolint时指定配置文件

bash 复制代码
nerdctl run --rm -i -v /root/hadolint-demo/hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint < Dockerfile
bash 复制代码
-:1 DL3006 warning: Always tag the version of an image explicitly
-:2 SC2154 warning: node_verion is referenced but not assigned (did you mean 'node_version'?).
-:2 DL3009 info: Delete the apt-get lists after installing something
-:2 DL3015 info: Avoid additional packages by specifying `--no-install-recommends`
-:4 DL3045 warning: `COPY` to a relative destination without `WORKDIR` set.
-:5 DL3003 warning: Use WORKDIR to switch to a directory
-:5 DL3016 warning: Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`

为了确保Dockerfiles的质量和安全性,将Hadolint集成到开发工作流程中是一个明智之举。这样可以在代码编写、提交前以及持续集成(CI)过程中自动检测潜在问题。以下是一些常见的集成方式:

  • 代码审查平台集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#code-review

  • 持续集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#continuous-integration

  • 编辑器集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#editors

  • 版本控制集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#version-control

相关推荐
易保山25 分钟前
MIT6.S081 - Lab10 mmap(文件&内存映射)
linux·操作系统·c
禅与Bug的修复艺术34 分钟前
JAVA后端开发常用的LINUX命令总结
java·linux·面试·java面试·后端开发·java后端·面试经验
北冥有鱼被烹2 小时前
【微知】/proc中如何查看Linux内核是否允许加载内核模块?(/proc/sys/kernel/modules_disabled)
linux·服务器
qq_273900232 小时前
CentOS系统防火墙服务介绍
linux·运维·centos
小余吃大鱼2 小时前
CentOS中在线安装Docker(超详细)
linux·docker·centos
程序员JerrySUN3 小时前
驱动开发硬核特训 · Day 19:字符设备驱动实战(控制 LED)
linux·驱动开发
小灰灰__3 小时前
Linux安装ffmpeg7.1操作说明
linux·运维·服务器
Zz_waiting.3 小时前
网络原理 - 9
linux·服务器·网络·网络协议·tcp/ip
你又食言了哦3 小时前
linux下使用wireshark捕捉snmp报文
linux·网络·wireshark
fyr897574 小时前
Ubuntu 下编译goldfish内核并使用模拟器运行
android·linux