[FAST] Super Flash Docker for Real-Time Testing
Everton Tenorio

Everton Tenorio @evertontenorio

About: A system with bugs, some already fixed. 🇧🇷 💻 🛡️ ☕ 🥁 🏖️

Location:
Brazil
Joined:
Aug 21, 2023

[FAST] Super Flash Docker for Real-Time Testing

Publish Date: Jan 28
0 0

Today's Fast and Simple Tip is about docker.

To quickly test a Node.js application in development, without a build or Dockerfile, I use this command:

docker run -d --rm --entrypoint /app/run.sh -v $(pwd):/app -p 8080:8080 node:20-alpine
Enter fullscreen mode Exit fullscreen mode

Here, the run.sh script in the current directory (/app) can be something like this:

#!/bin/sh
cd /app
[ -f package.json ] && npm install || echo "No package.json found, skipping install"
npm run serve -- --host 0.0.0.0
Enter fullscreen mode Exit fullscreen mode

How does it work and why use it?

  • -d: Runs in the background, freeing up the terminal.
  • --rm: Removes the container when stopped, perfect for disposable tests.
  • -v $(pwd):/app: Syncs your local code with the container in real time.
  • --entrypoint /app/run.sh: Runs your custom script, ignoring the default entrypoint of the image.
  • -p 8080:8080: Exposes the port for browser access (e.g., http://localhost:8080).

The run.sh script checks if a package.json exists before installing dependencies, preventing errors, and starts the server (ideal for Vue.js, React with Vite, etc.). This eliminates the need to build a Docker image during development, speeding up testing.

Tip:

If you run multiple containers, avoid using a fixed --name to prevent conflicts. Docker automatically generates random names.

Comments 0 total

    Add comment