We reduced a real Node.js production Docker image from 1.2GB to 78MB

(the-practical-developer.online)

27 points | by milkikomasiko 10 hours ago ago

17 comments

  • 1a527dd5 9 hours ago
    • simondotau 9 hours ago

      Yep, it’s also AI slop. @dang ?

  • tpaksoy 9 hours ago

    We had issues running our Node app on alpine. Specifically the dns lookup for our API calls were taking several hundred milliseconds *every* time.

    Switching to debian reduced it to microseconds.

    Does anyone here know what I was doing wrong with alpine?

    • ashishb 9 hours ago

      Alpine is a bad idea for a non-trivial application written in Python, Node.js, or any other interpreted language.

      Too many weird edge cases to deal with, especially related to Alpine using musl libc instead of glibc.

      At best, your builds are slower.

      At worst, certain code paths are broken.

      • apimade 6 hours ago

        Alpine is a great choice.. Provided you understand what’s included, and the ramifications it has on the stack you’re trying to work with.

        99 times out of 100 it’s a terrible choice for an enterprise.

      • stavros 9 hours ago

        I had this experience as well, nowadays I use Debian slim. Too much random breakage in Alpine.

    • Tiberium 9 hours ago

      Musl is much less optimized than glibc, random example: https://andygrove.io/2020/05/why-musl-extremely-slow/

  • 9 hours ago
    [deleted]
  • Eighth 9 hours ago

    Good post. Using slim is the easiest and biggest impact change.

  • coolThingsFirst 9 hours ago

    Ditch docker and use Golang to bring it to 4MB.

    • stavros 9 hours ago

      Ditch Golang and use a textfile containing the text "Hello world!" to bring it to 12 bytes.

      • coolThingsFirst 8 hours ago

        That's not going to work, that's a static file.

        Golang gives you a web server as a staticly linked binary.

        • stavros 8 hours ago

          If we're disregarding requirements, I figured I'd disregard some too.

          If the question is "I need to containerize my Node app, how do I make it small?" the answer can't be "don't containerize it and don't use Node".

          • coolThingsFirst 5 hours ago

            What problem does Docker solve which is fundamental? None. Zero. Zilch. I've used it two times and except burning dev time with its random BS has no benefit whatsoever. I guess if you run a 200K line app and working with 20 devs will make things slightly easier?

            On M1 launching the docker containers lagged the entire system.

            Trying to mount a volume caused issues. (known issue) The official web app advertisies it as multiplatform which it's not.

            Anything more complex than hello world become a nightmare on Docker. PM2 as process manager and simple bash scripts demolish Docker which sounds too good in theory but is half-baked in practice.

  • wxw 9 hours ago

    This website seems entirely filled with AI slop articles targeted towards software eng.

  • hottrends 9 hours ago

    [flagged]