Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk7 min

How to Run Loki Screenshot Tests in Docker (Storybook Visual Regression)

Set up Loki visual regression for Storybook with Chrome in Docker: commands, Docker network and mount flags, a CI script, stability tips and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run Loki in Docker, install Loki in your Storybook project, choose the chrome.docker target, start the Storybook server yourself, then run yarn loki update once to create baselines and yarn loki test on every change. Loki launches Chrome inside a container, captures each story, and compares it with the approved reference images. This guide gives the full sequence, the Docker-specific flags, a CI-style script, and fixes for the failures you are most likely to hit.

A caveat first: Loki’s getting-started and CLI pages both show a last-updated date of 2024-08-27. Treat the defaults quoted below (Node version, Chrome image tag, folders) as documented values to check against your installed Loki version, not as guarantees for today.

As an Amazon Associate I earn from qualifying purchases.

What you need before you start

  • A Storybook project. Loki is a visual regression tool for Storybook; it screenshots stories.
  • Node 16 or newer, according to the Loki getting-started guide (historical documentation, last updated 2024-08-27; confirm against your installed release).
  • Docker, needed for the chrome.docker target. Local Chrome (documented as Chrome 59+) is only an optional alternative, and screenshots from a local browser vary by operating system, which is the problem Docker avoids. Loki’s stated aims include reproducibility across operating systems and CI support; those are project goals, not measured guarantees.
  • GraphicsMagick only if you pick the gm diff engine.

Step-by-step: first run

  1. Install and initialize Loki.
    yarn add loki --dev
    yarn loki init

    This is the setup the official guide gives. The init step generates Loki’s configuration, including the Docker-based Chrome target.

  2. Start Storybook. Loki does not do this for you. The docs say: “For loki to be able to access your stories you must start the storybook server.”
    yarn storybook

    Leave it running in its own terminal.

  3. Create the reference screenshots.
    yarn loki update

    Loki captures every story in the Docker Chrome container and writes baselines to ./.loki/reference.

  4. Look at the baselines. A reference that captures a spinner, an error state or a half-rendered component will make every later run meaningless. Fix the story before committing.
  5. Commit the .loki/reference folder. The guide says Git LFS is optional, so it is a choice for large repositories, not a requirement.
  6. Run the comparison.
    yarn loki test

    Fresh captures go to ./.loki/current. Any story that differs from its reference produces an image in ./.loki/difference.

  7. Review, then approve intended changes.
    yarn loki approve

    This promotes the current screenshots to references. The CLI also suggests a command that approves only the failing stories, which is safer than approving everything. Commit the updated references with the code change that caused them.

Docker options that matter

The CLI reference documents these Docker-related flags:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Flag What it does Use it when
--chromeDockerImage Selects the Chrome container image. The documented default is yukinying/chrome-headless-browser-stable:118.0.5993.117 (2024 docs). You need to pin or change the Chrome build. Treat the default tag as a historical example and check what your Loki version expects.
--dockerNet Passes a Docker network mode, such as host or bridge. The container cannot reach the Storybook server on the host.
--chromeDockerUseCopy Copies local stories into the container instead of using a volume mount. Volume mounts fail, which can happen when Docker itself runs remotely or inside another container in CI.
--dockerWithSudo Runs Docker commands with sudo. Your user is not allowed to call Docker directly.

Other CLI options relevant to this setup are --host and --port, for Storybook servers not on the default address. The docs list three diff engines: pixelmatch, looks-same and gm, and default folders ./.loki/reference, ./.loki/current and ./.loki/difference.

Passing arguments through Yarn or npm

The CLI docs say to prepend arguments with -- so the package manager forwards them to Loki, and illustrate it with:

yarn loki test -- --port 9009

Argument forwarding differs between package-manager versions. If a flag seems ignored, run the Loki binary directly (for example through npx loki test --port 9009) and compare.

Example: a CI-style script

This is an illustrative script built from the documented commands, not an official template. It starts Storybook in the background, waits for it, runs Loki, and always stops the server. Adjust the port, wait mechanism and flags for your project.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#!/usr/bin/env bash
set -euo pipefail

yarn storybook --ci &
SB_PID=$!
trap 'kill $SB_PID' EXIT

# wait until Storybook answers (port 6006 is Storybook's usual default)
until curl -sf http://localhost:6006 > /dev/null; do sleep 2; done

yarn loki test

If this fails because the container cannot see the server, add the network flag, for example yarn loki test -- --dockerNet host. If it fails because of volume mounting, try --chromeDockerUseCopy. The official docs do not establish one universally correct Docker network setup for every CI environment, so expect to test which combination your runner needs.

Making runs stable

Failed network requests fail the test

By default, Loki’s configuration fails a story when one of its network requests fails. Stub APIs, use local fixtures, and avoid external fonts or images that may be unreachable from the container. This is the right default: a screenshot with a broken image is not a valid baseline.

Animations

Animation timing changes pixels between runs. The flaky-test guidance documents disabling animations through the chromeEnableAnimations option. Disable them unless the animation itself is what you want to test.

Asynchronous stories

If a story needs time to finish rendering, Loki documents an async callback pattern so the story can signal when it is ready, rather than relying on luck with timing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshooting

Symptom Likely cause Fix
Loki cannot fetch stories or reports a connection error Storybook is not running, or is on another host or port. Start yarn storybook first; pass --host / --port if non-default.
Storybook works in your browser but not from the container The container’s network mode cannot reach the host server. Try --dockerNet host or bridge and confirm the server is not bound only to a loopback address the container cannot reach.
Docker permission denied Your user cannot run Docker. Add the user to the Docker group, or use --dockerWithSudo.
Stories are missing or empty in the container Volume mount problem. Use --chromeDockerUseCopy.
A flag appears to have no effect The package manager swallowed it. Add -- before Loki’s arguments, or call Loki directly.
A story fails with a network error A request in the story failed, and the default is to fail the test. Mock or serve the resource locally.
Diffs appear on unchanged stories Animations or async rendering. Disable animations with chromeEnableAnimations; use the async completion callback.
Image pull or Chrome behaviour differs from the docs The documented default image is from 2024 documentation and may not match your Loki version. Check your installed version’s docs, or set --chromeDockerImage explicitly.
Everything differs after a Chrome image change A new Chrome build renders text and anti-aliasing slightly differently. Pin the image, and regenerate and commit references in the same change as any image bump.

Review habits that keep baselines trustworthy

  • Open both current and difference images before approving; do not approve blindly after a red run.
  • Prefer approving only failures over approving everything.
  • Keep reference images in the same pull request as the UI change, so reviewers see the visual diff beside the code.
  • Generate baselines in Docker, never from a local Chrome, so CI and developer machines match.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

Loki answers a specific question: did this Storybook component change? If what you actually need is a screenshot of a page or URL (for monitoring, previews, reports or an AI agent), you do not need a Storybook server, Docker image or network flags. ScreenshotNeo is a website screenshot API: one GET request with a URL returns a PNG, JPEG, WebP or PDF. Full options are in the ScreenshotNeo docs.

Best Value
Docker Container Linux Devops Programming Coding T-Shirt
  • Docker, Docker Swarm, Docker Compose, Programmer, Developer, Coding, Programming, Software Engineer, Code, DevOps, Deploy, Deployment, Kubernetes, Salt, Puppet, Chef, Terraform, Container, AWS, Azure, Cloud, Geek, Funny, Computer, Software, Tech, IT
  • Integration, Scrum, Compile, Compilation, Science, Bug, Debug, Python, Linux, Java, Javascript, Scala, Dotnet, Kotlin
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie banners, newsletter popups and chat widgets are removed before the shot (60+ known consent platforms are handled, and each step can be turned off).
  • Bot checks, blank pages, timeouts, failed loads and cache hits are never billed; the X-Page-Verdict and X-Billed response headers tell you which it was.
  • Full-page capture, single-element capture by CSS selector, dark mode, device presets, waiting for a selector or network idle, and HTML/CSS to image are all available on every plan.
  • An MCP server (tools take_screenshot, get_page_info, capture_pdf) lets AI agents in Claude, Cursor or any MCP client take screenshots.
  • 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.

Create a free ScreenshotNeo account and make your first call in a minute.

Frequently Asked Questions

Does Loki start Storybook for me?

No. You must start the Storybook server before running Loki, as the project documentation states.

Can I use Loki without Docker?

Yes, Loki can target a locally installed Chrome (documented as Chrome 59+), but rendering can differ between operating systems, which is why Docker is used for consistent baselines.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do I need Git LFS for the reference images?

No. The getting-started page describes Git LFS as optional.

Is Loki a replacement for a screenshot API?

No. Loki compares Storybook stories against approved baselines. A screenshot API captures arbitrary URLs and returns an image or PDF.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.