Notes
The words
A few words. An image is a read only package: an operating system layer, a runtime like Node, and the application. A container is a running copy of an image, isolated from the machine and from other containers. Port mapping connects a port on your machine to a port inside the container. A volume keeps data after a container is removed. And environment variables configure the container when it starts.
- image: a read-only recipe (OS + runtime + app)
- container: a running copy of an image, isolated
- port mapping: host 8080 → container 8080
- volume: data that outlives the container
- env vars: configure at start
ShopRung's Dockerfile
Here is ShopRung's real Dockerfile. From starts with a small official Node twenty four image. Workdir sets the folder. Copy brings in package dot json, the source and the public files; ShopRung has no dependencies to install. Env sets the port, expose documents it, and CMD is the command that runs when the container starts. Testers should be able to read files like this, because they define the environment under test.
FROM node:24-alpine WORKDIR /app COPY package.json ./ COPY src ./src COPY public ./public ENV PORT=8080 EXPOSE 8080 CMD ["node", "--disable-warning=ExperimentalWarning", "src/server.js"]
Run it
ShopRung's compose file builds the image, maps port eight thousand and eighty, passes the SHOPRUNG BUGS variable and keeps the database in a volume. Up with build and dash d starts it in the background. Ps shows what is running, logs dash f follows the app's log, and exec opens a shell inside. Down stops it; down dash v also deletes the volume, which gives you a clean database. Set SHOPRUNG BUGS to turn on a practice bug.
docker compose up --build -d docker compose ps docker compose logs -f shoprung docker compose exec shoprung sh docker compose down # stop docker compose down -v # + data # turn on a practice bug: SHOPRUNG_BUGS=coupon-boundary \ docker compose up -d
App plus tests
To run tests against the app, add a second service in a separate compose file for tests. The shop gets a health check that calls its health endpoint every two seconds. The e2e service uses the official Playwright image, which already contains the browsers and their system libraries. It depends on the shop with the condition service healthy, so the tests start only when the shop answers. No sleeps, no guessing.
services:
shoprung:
build: ./shoprung
healthcheck:
test: ["CMD", "wget", "-qO-",
"http://localhost:8080/api/health"]
interval: 2s
e2e:
image: mcr.microsoft.com/
playwright:v1.63.0-noble
depends_on: { shoprung: ... Names, not localhost
A common surprise: inside the tests container, localhost means the tests container itself. Compose puts services on one network where each service name is a host name, so the base URL is http colon slash slash shoprung colon eight thousand and eighty. Your suite reads it from an environment variable. The tests folder is mounted as a volume, and exit code from e2e makes the whole command pass or fail with the test result, which is exactly what CI needs.
depends_on:
shoprung:
condition: service_healthy
environment:
BASE_URL: http://shoprung:8080
working_dir: /e2e
volumes: ["./e2e:/e2e"]
command: npx playwright test
docker compose -f compose.test.yaml
up --exit-code-from e2e Pin the image
Pin the image tag to the same Playwright version as your package file; a mismatch is a classic error, because each Playwright release expects its own browser builds. For Selenium, the Selenium project publishes Grid images: a hub with Chrome and Firefox nodes, or a standalone Chrome image. Never use the latest tag in CI. GitHub Actions can run a whole job inside an image with the container key, and Jenkins with a Docker agent.
- Playwright: mcr.microsoft.com/ playwright:v1.63.0-noble = same version as package.json
- Selenium Grid: selenium/hub + node-chrome, node-firefox or standalone-chrome
- tags pinned, never :latest
- CI: run the job inside the image (container: in Actions, agent { docker } in Jenkins)
Testcontainers
Testcontainers is a library that starts containers from inside test code. In Java, a container field annotated with at container starts a real Postgres database before the tests and removes it afterwards; the test asks it for the connection URL. You get a real database, fresh for every run, instead of a mock or a shared server. Libraries exist for Python, Node, dot net and Go too. It needs a Docker engine on the machine.
@Container
static PostgreSQLContainer<?> db =
new PostgreSQLContainer<>(
"postgres:17-alpine");
@Test void savesOrder() {
var url = db.getJdbcUrl();
// real database, fresh per run
}
// also: Python, Node, .NET, Go Why it matters
What you gain. The same versions everywhere. Fresh data for each run, because a new container starts clean. A new team member runs one command instead of following a long setup document. CI agents only need Docker. And you can reproduce a CI failure on your laptop with the same image. The costs are image size, start up time, and learning Docker, which is now a normal expectation for SDET roles.
- same versions everywhere
- fresh data each run (down -v, new container)
- new team member: one command
- CI agents stay simple
- reproduce a CI failure on your laptop exactly
- cost: image size, start time, Docker knowledge
Common mistakes
Docker mistakes. Calling localhost from inside a container when the app is another service. Sleeping instead of using a health check. Latest tags, so the environment changes without anyone noticing. A Playwright image that does not match the installed Playwright version. Old volumes that keep data between runs by accident. And secrets copied into images, where anyone who pulls the image can read them.
- localhost from inside a container
- sleep instead of a healthcheck
- :latest image tags
- browser image version not matching Playwright
- data kept between runs by accident (old volume)
- secrets baked into images
Say it like this
In the interview: compose starts the application with a health check, and the tests run in the official Playwright image, pinned to our version. The tests wait for the service to be healthy and use the service name as the base URL, and exit code from makes CI pass or fail. Each run gets fresh volumes. For cross browser runs we use Selenium Grid images, and Testcontainers gives integration tests a real, throwaway database.
- "Compose starts the app with a healthcheck and the tests in the pinned Playwright image;
- tests wait on service_healthy
- and use the service name as the base URL. exit-code-from makes
- CI pass or fail. Fresh volumes
- per run, Selenium Grid images
- for cross-browser, and Testcontainers for real DBs."