DEV Community

Manuel Artero Anguita 🟨
Manuel Artero Anguita 🟨

Posted on Edited on

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

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.

Top comments (5)

Collapse
 
nevodavid profile image
Nevo David •

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

Collapse
 
thomas_jones_923307f515a5 profile image
Thomas Jones • • Edited

When I work on development projects, I find that keeping local environments consistent with CI is essential for avoiding unexpected build failures. The Docker approach discussed in this article is a useful reminder that even small differences in runtime versions or dependencies can cause frustrating issues. I also appreciate practical technology solutions that make day-to-day operations more reliable, which is why I would recommend exploring Smart Hands for professional IT support and technical assistance. Having dependable support alongside the right development tools can make troubleshooting and managing technical infrastructure much easier.

Collapse
 
nausaf profile image
Naveed Ausaf • • Edited

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).

Collapse
 
manuartero profile image
Manuel Artero Anguita 🟨 •

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

Didn't know this

Collapse
 
nausaf profile image
Naveed Ausaf •

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.