-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Docker best practices - call for ideas #620
Comments
Idea: Start the production process with 'Node' command, avoid 'npm start' What is this about: 'npm start' won't pass KILL signal to the process which is very frequent at environments with dynamic scheduling like k8s, this will prevent a graceful shutdown Why is this important: Highly (only) related to Node.js |
Idea: Set Docker memory limits which are in-par with v8 memory limit What is this about: In recent version s,v8 memory allocation is configurable, Docker & k8s also allows setting quotas, this should now be synchronized (I have to research on this better, for now it's just an idea) Why is this important: Highly related to Node.js/v8 |
Many things I can think of :-)
I have many more of these here: https://snyk.io/blog/10-docker-image-security-best-practices/ and don't let the title fool you, even though I have discussed them as the security angle, they are nonetheless all important practices to take on. |
Thank you the all-mighty @lirantal Adding one more: Idea: Graceful shutdown What is this about: When dockerized runtime kills a container, exiting efficiently makes the difference between disappointing ~1000 users vs zero errors Why is this important: The implementation (code examples) are highly related to the webserver |
I've got one more. Actually not sure if we have to add it to the docker best practices for node or to node best practices (I did not find it with a quick read) Idea: Install packages for production What is this about: When running npm install in the docker image, we should make sure to only install needed packages by running with the Why is this important: Do not ship devDependencies in your docker image. It could contain vulnerabilities and it adds weight to the image. |
Idea: Use the node user What is this about: before the CMD make sure you have a line with USER node. Why is this important: It restricts the permission of the app running not in root, better for security. |
By looking at nodejs/docker-node#1 they bring the following articles: |
@goldbergyoni True, I'll try to write something about it this week 😃 |
@goldbergyoni The best summary that I saw in 2019 about Nodejs and Dockerfiles best practices is from @BretFisher in the "Docker and Node.js Best Practices from Bret Fisher at DockerCon". The source from that talk here https://github.com/BretFisher/dockercon19. In most cases, I would write what he said in that talk. |
@bi0morph Thanks for bringing this gold stuff, I watched this video and would call it 'best Node video of 2019' :)
What title would you propose here? Keep test and production images as close as possible? Do you see a need for dev stage? I didn't see many developers who enjoy developing with Docker (for their own code)
Yes, great idea. What is the title here? don't leave secrets within images?
Why is this related to Docker? because the reinforced need to shut down gracefully? |
Couldn't spot there an example of a specific attack, did I miss it? |
@bi0morph a few things. I've been following the thread, thanks for the plug and everything's looking good, and I have some ideas:
|
One more idea - usage of .dockerfile linter like: |
Maybe something applicable from here http://docs.projectatomic.io/container-best-practices/ |
@BretFisher My two cents:
|
|
@bobaaaaa I kind of think the same of the purpose of multistage docker. I don’t really like using a build step to run tests. Do you have a separate docker build to run tests and linting ? Or do you run them outside of a docker (which for me ruins the interest of using docker)? Or maybe something else? |
When your CI is called Jenkins than multistage docker with lint and test makes sense (maybe). I prefer some container based CI solution like TravisCI, CircleCI or currently github actions. I used all of them in different projects and I'm quite happy. From my current project:
Because of the ubuntu images I don't use multistage docker at all (currently). Luckily I don't need docker-compose. |
Those are some things I've seen in my company:
|
This is not a good advice actually since build-args are cached in the store where the image is built. Instead you should use multi-stage builds (see number 9 here: https://snyk.io/blog/10-docker-image-security-best-practices/)
Just please don't make it a habit of putting secrets there 🙏
👌 |
Hello there! 👋 |
Given the immense popularity of Docker and the need to harden it different per platform (see ideas below) - we'd like to start writing a Docker best practices section.
You're welcome to contribute ideas and write best practices - writing and brainstorming will people is an amazing way to deepen your Docker understanding.
At first, we want to collect ideas for best practices, solidify a list of 10-15 bullets and then assign the ideas to writers.
@BretFisher @lirantal @giltayar @js-kyle @BrunoScheufler @kevynb
The text was updated successfully, but these errors were encountered: