My Local Works™: A Docker Tale (+ Handy Script)
Manuel Artero Anguita 🟨

Manuel Artero Anguita 🟨 @manuartero

About: Father & happily married 👨‍👩‍👧. Senior Software eng. based on 🇪🇸. TV Apps at @Telefonica. React ⚛️ Professor in a master's program. Js 🟨 Ts 🟦

Location:
Madrid, Spain
Joined:
Jan 18, 2022

My Local Works™: A Docker Tale (+ Handy Script)

Publish Date: Jun 13
2 4

Today I faced one of those "this is Witchcraft" moments.

CI was failing for a specific commit. I checked out that exact commit locally… everything clean. Built fine. No errors.

Witchcraft 🧙! "I'm exactly on the same commit, and in my local machine it does build with no problems".

This was a JS project. And in JS (TS doesn’t matter here), my first suspect is always dependencies.
So, I removed node_modules and rebuilt from scratch.

Witchcraft x2 🧙🧙! still couldn’t reproduce the error.

So I went to the workflow file and started following step by step what CI was doing.

Witchcraft x3 🧙🧙🧙! it can't b... oh wait.

Of course the CI runs everything in a clean, pure node:20-alpine image.

So I fired up the same container locally to see what was going on.


Now, this is just he context to what i want to share:
I use this tiny script like...a lot.

If you use oh-my-zsh, you can add it to ~/.oh-my-zsh/custom/docker-run.zsh (adapt to your setup):

docker-run.zsh

function docker-run() {
    if [[ -z "$1" ]]; then
        echo "Usage: docker-run <image>"
        return 1
    fi

    local container_image="$1"
    local workdir="/app"

    docker run --rm -it \
        -v "$PWD:$workdir" \
        -w "$workdir" \
        "$container_image" \
        /bin/sh
}
Enter fullscreen mode Exit fullscreen mode

Super simple. Just go to your project folder:

 docker-run node:20-alpine
/app #
Enter fullscreen mode Exit fullscreen mode

The devil’s in the details:

  • --rm so the container is gone when you exit
  • $PWD mounts the current project inside the container
  • it so you’re dropped into the terminal
  • sh cause these minimal images usually don’t have bash

Back to the mysterious "Witchcraft!🧙 error" —>
Turned out there was a node version mismatch: v20.18.1 locally vs. v20.19.2 in the container.

No magic for today.

--
thanks for reading.

Comments 4 total

  • nausaf
    nausafJun 15, 2025

    Some images such as the slim .NET Core runtime images, doesn't have a shell at all. docker debug can be used in this case (locally of course).

    • Manuel Artero Anguita 🟨
      Manuel Artero Anguita 🟨Jun 15, 2025

      Wait thise don’t have ANY shell?!?? No way!

      Didn't know this

      • nausaf
        nausafJun 15, 2025

        This is a Microsoft post detailing the rationale for their so-called chiselled images.

        The runtime .NET Core images I use in Production have no shell and this took me by surprise at first! I use Production images, with no modifications or customisations using build ARGs etc, in continuous testing locally (with Docker Compose) and in CI. This ensures I am testing exactly the image taht would go into Production (a post on this due soon, I'll tag you).

        But locally, I can at least docker debug to have a look when things aren't working out.

  • Nevo David
    Nevo DavidJun 15, 2025

    Pretty cool stuff, been there way too many times - script like that saves me every single time.

Add comment