-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Improve Dockerfile: smaller image and default non-root user #7470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 1.19-alpine to 1-alpine to ease the update process of nginx base image - remove unnecessary "apk update" - use the flag --chown and --chmod to avoid duplicate of files resulting of a "RUN chmod/chown" command: 20MB+ saved in the final docker image - non-root (nginx, uid=101) user as default for security best practice
|
@Blaimi can you take a look at this PR and share your opinion? Thanks in advance! |
|
@damienleger thanks for the update, so you are still getting a smaller image even without using |
Yes, 11MB smaller (less than before, but master changed a lot since then). Below you can see |
|
@damienleger PR merged! Thanks much for the continued followup to get this PR merged, and thanks for the contribution! |
|
@damienleger So some unfortunate news for this PR... it breaks SwaggerUI's Jenkins deployment jobs so I will have to revert it. Fyi, the issue is that the current Docker version used for deployment is old, and does not support either of
I appreciate the effort on this PR, and it definitely would have been nice to trim a Docker layer. Hopefully we can revisit this topic in the future if/when deployment jobs versions get upgraded. |
|
@damienleger Update, good news on this PR, the deployment configuration was updated by the Swagger DevOps team, so this PR remains intact and is included in v4.10.3 release! |
|
Good news 🙂 FYI,
|
of a "RUN chmod/chown" command: 20MB+ saved in the final docker image
Description
With #5476
RUN chmodhave been added to make the docker container runnable on any non root user for Openshift. Those command create docker layer with files duplicate of 20MB+This can be seen with https://github.com/wagoodman/dive (e.g.
CI=true dive swaggerapi/swagger-ui:latest)Result:
My changes use buildx flag
--chown / --chmodto keep the "run with any non root user" feature, but without create additional docker layer since there is no extra RUN command. Resulting in a smaller image. The chmod is done on directory only, which doesn't increase image size.docker buildx build --tag=localbuild:1 --pull .pull is necessary to ensure last version of
1-alpinefrom the remote registry is downloaded. This is to avoid update the FROM line in Dockerfile regularly.Now with dive:
Motivation and Context
Have a small docker image and follow run as non-root best practice reco.
How Has This Been Tested?
on Ubuntu 20.04.2 LTS server with docker community edition 20.10.8
build via
docker buildx build --tag=localbuild:1 --pull .and tested with
docker run --rm -p 8080:8080 localbuild:1to run on defaultnginxuserdocker run --rm -p 8080:8080 -u nobody localbuild:1to run on another (nobody) non root userScreenshots (if appropriate):
Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests