Live data from Hacker News

Writing Dockerfiles for Node.js Web Apps

blog.hasura.io

11–20 of 37 posts

Re: Writing Dockerfiles for Node.js Web Apps

#12
I like the new multi stage Dockerfile concept in the later Docker versions. It makes it easy to define Dockerfiles that both builds and runs your code, while still separating build and run dependencies. I have used this for both Node and Go projects. As long as the build output is not too spread out in terms of paths copying your build artifacts over to the other Dockerfile stages should not be a big issue.

Re: Writing Dockerfiles for Node.js Web Apps

#13
post #11

I'm surprised they haven't included a process manager for the production build. In my experience it allows for much easier 0-sec downtime updates and load balancing. We're using pm2 [1] for this if anyone's interested. [1] https://github.com/Unitech/pm2

If you use container orchestration platforms like Kubernetes, this is not required, as restarts load balancing etc. are handled by the orchestrator.

Re: Writing Dockerfiles for Node.js Web Apps

#14
I completely get the purpose and benefit of Docker. More and more though I'm becoming convinced that for many settings and problems Docker actually creates more problems and meaningless ritual because Docker rapidly is becoming the standard way of deploying software with hardly anyone asking about the reasons anymore.

Docker recreates many of the benefits the Java platform has had from the start (in addition to some other aspects but that's the main selling pont). So, if you have a non-Java application Docker might indeed be a worthwhile choice. The thing is, even with Java platform-independence and deployment standardization for web apps / SaaS-type applications has always been a minor selling point.

Those features are certainly important if you need to rapidly provision and scale your application on many different machines in a distributed environment you don't completely control.

In reality, for many applications today this simply isn't the case though. The main motivator behind that feature after all was the concept of desktop applications that are deployed to each user individually.

So, with Docker we now indiscriminately add an additional layer of complexity on top of existing applications regardless of the actual problems this might solve.

Re: Writing Dockerfiles for Node.js Web Apps

#15
post #11

I'm surprised they haven't included a process manager for the production build. In my experience it allows for much easier 0-sec downtime updates and load balancing. We're using pm2 [1] for this if anyone's interested. [1] https://github.com/Unitech/pm2

If you use container orchestration platforms like Kubernetes, this is not required, as restarts load balancing etc. are handled by the orchestrator.

Does Kubernetes support graceful reload of containers, with 0 downtime? I'd be very interested if so.

Re: Writing Dockerfiles for Node.js Web Apps

#16
post #4

> Using an appropriate base image (carbon for dev, alpine for production). Isn't using the same container everywhere the actual selling point for containers?

Depends on the use-case. For development, you would need to install some system dependencies, access to bash for debugging etc and hence the full blown base image. In production, you want the image sizes to be minimal and hence alpine base image. Also reduces the attack vector.

Re: Writing Dockerfiles for Node.js Web Apps

#17
post #15

Earlier quoted context omitted.

If you use container orchestration platforms like Kubernetes, this is not required, as restarts load balancing etc. are handled by the orchestrator.

Does Kubernetes support graceful reload of containers, with 0 downtime? I'd be very interested if so.

It does. Look at https://kubernetes.io/docs/concepts/workloads/controllers/de...

Re: Writing Dockerfiles for Node.js Web Apps

#18
post #15

Earlier quoted context omitted.

If you use container orchestration platforms like Kubernetes, this is not required, as restarts load balancing etc. are handled by the orchestrator.

Does Kubernetes support graceful reload of containers, with 0 downtime? I'd be very interested if so.

[deleted]

Re: Writing Dockerfiles for Node.js Web Apps

#19
post #15

Earlier quoted context omitted.

If you use container orchestration platforms like Kubernetes, this is not required, as restarts load balancing etc. are handled by the orchestrator.

Does Kubernetes support graceful reload of containers, with 0 downtime? I'd be very interested if so.

Yes, it does. Kubernetes can perform rolling updates [1].

One scenario is that when you rollout a new version, the old container will only be killed when new one is up and running. If there are many replicas running, Kubernetes will replace them with new versions one by one. And all of this behaviour is highly configurable.

[1] https://kubernetes.io/docs/tutorials/kubernetes-basics/updat...

Re: Writing Dockerfiles for Node.js Web Apps

#20
post #2

Nice post, and very close to my experiences with Dockerfiles for node. To the author: could you elaborate on the differences between carbon and alpine base images please? I can obviously go look this up, but this was the one part of the guide that was new to me. Your description wasn't enough to give me a complete understanding, so perhaps you could explain a bit more about carbon and alpine? Thanks.

carbon is the latest LTS (Long Term Support) version of Node. Instead of using the latest version, which can have breaking changes and possible drop of support in the future, it is recommended to use LTS version just to ensure using a stable + well supported version. alpine base images are generally used to cut down the image size for production, because they are very minimal and works well for most use-cases. But yo…

Thanks! You've given me something new to try out :)
Post reply on HN