Dockerfile Linter and Optimizer
Paste a Dockerfile to get scored findings with line numbers and fixes, then an automatically improved version, a multi-stage example and a .dockerignore.
브라우저에서 실행됩니다. 파일은 기기 밖으로 나가지 않습니다. 확인하는 방법 보기
…
사용 방법
- 1Paste the Dockerfile
Paste or open your Dockerfile.
- 2Read the score
Check the grade, finding count and number of stages.
- 3Work through findings
Filter by level and read the line, rule and fix.
- 4Open the rewrite
Choose the automatic fixes and compare the new score.
- 5Use the templates
Adapt the multi-stage example and .dockerignore.
- 6Download
Save the findings, the rewritten Dockerfile or the templates.
이 도구 소개
Most Dockerfiles work. The problems show up later: images that grow to a gigabyte because package caches stay in the layers, builds that reinstall every dependency after a one-line code change because the whole source is copied first, containers that run as root, secrets baked into image history, and a latest tag that silently pulls a new base image next month. These issues are easy to spot once you know the patterns, and a linter can check them every time. This tool reads a Dockerfile, joins continuation lines, and checks each instruction against 26 rules covering base images, users, layer order and caching, package manager hygiene, secrets in ENV and ARG, shell form commands, ADD versus COPY, risky commands such as curl piped into a shell, and missing health checks. It scores the file, explains each finding with a fix, and produces a rewritten Dockerfile that applies the safe automatic fixes, so you can compare before and after.
Rules
Base images without a tag or with :latest are warnings, while stage names, scratch and build arguments are skipped. The final stage must set a non-root USER. Installing dependencies after COPY . . is flagged because every code change invalidates that layer. apt-get install should run with update in the same RUN, with -y, --no-install-recommends and a cleanup of /var/lib/apt/lists; apk add should use --no-cache and pip --no-cache-dir; npm ci is suggested over npm install. ENV and ARG values with names like PASSWORD, TOKEN or SECRET are errors because they stay in the image history. Other rules cover MAINTAINER, ADD for local files, ADD from URLs without --checksum, relative WORKDIR, EXPOSE 22, shell-form CMD and ENTRYPOINT, sudo, chmod 777, cd inside RUN, consecutive RUN lines and single-stage builds that run compilers.
Score
Errors cost 15 points, warnings 6 and notices 2, starting from 100.
Rewritten Dockerfile
The optimizer converts MAINTAINER to a LABEL, local ADD to COPY, adds the missing apt flags, update and cleanup, apk --no-cache and pip --no-cache-dir, optionally switches npm install to npm ci, converts simple CMD and ENTRYPOINT to exec form, can merge consecutive RUN lines and adds a USER before the start command. The new file is linted again so you see the score change, and you can load it back as input to keep editing with undo.
Templates
A Node multi-stage example shows the pattern of a dependency stage, a build stage and a slim final stage running as the node user with a health check. A starter .dockerignore keeps .git, node_modules and .env out of the build context.
Limits
Checks are static text rules; the tool does not run a build, pull images or scan packages for vulnerabilities. Base image tags, secrets and layer order need a human decision, so they are reported but not rewritten.
풀이 예시
A Node service Dockerfile of eleven lines scored 21 with 17 findings: node:latest, no USER, MAINTAINER, a relative WORKDIR, ADD . . followed by npm install, three separate RUN lines, apt-get install without update, -y or cleanup, a secret in ENV and a shell-form CMD. The rewritten version switched to COPY, npm ci, a single apt-get update and install with --no-install-recommends and cleanup, exec-form CMD and USER node, raising the score to 59. Moving the secret to a build secret, pinning node:22-alpine and copying package files before installing took it above 90.
한눈에 보기
- 카테고리: 개발 및 데이터
- 브라우저에서 실행되며 가입도 업로드도 필요 없습니다.
- 입력한 정보는 기기에 머뭅니다.
- 영어로 제공됩니다.
- 콘텐츠 최종 검토일:
- 공식 출처: Docker Docs, Building best practices and Dockerfile reference
자주 묻는 질문
Why is :latest a problem?
It points to whatever was pushed most recently, so the same Dockerfile can build a different image next week. Pin a version, or a digest for full reproducibility.
Why should the container not run as root?
If the app is compromised, root inside the container has far more power, including over mounted files and some kernel interfaces. A non-root user limits the damage.
Why copy package files before the rest of the source?
Docker caches each layer. If dependencies install before the code is copied, a code change reuses the cached dependency layer, which can save minutes per build.
How should I pass secrets during a build?
Use BuildKit secret mounts, RUN --mount=type=secret,id=..., which make the secret available to one command without storing it in a layer. Runtime secrets belong in the orchestrator, not the image.
Does the rewrite change behaviour?
The automatic fixes are chosen to be safe, but npm ci needs a lock file and exec-form CMD does not expand shell variables, so review the diff and test the build.
Is my Dockerfile uploaded?
No. Linting and rewriting run in your browser; the text is saved only as a local draft.
