Of course! This is an excellent setup for modern web development and E2E testing. Here is a complete Docker Compose project that fulfills all your requirements.
We will create two services:
goserver: A lightweight Go container that compiles and runs a simple web server to serve a static index.html.
devclient: A container based on the official Playwright image, with neovim and git added. It will have both Node.js and Python environments ready for you to write and run Playwright scripts against the goserver.
Project Directory Structure
First, let's lay out the files and folders. Create this structure in your project root:
go-playwright-dev-env/
├── dev-client/
│ ├── Dockerfile
│ ├── test.js # Example Node.js Playwright script
│ └── test.py # Example Python Playwright script
│
├── goserver/
│ ├── static/
│ │ └── index.html
│ ├── Dockerfile
│ └── main.go
│
└── docker-compose.yml
File Contents
Now, let's fill in the contents for each file.
1. The Go Web Server (goserver)
This service will compile a tiny Go application into a minimal Docker image to serve your static file.
📁 goserver/static/index.html
A simple HTML file for the server to serve.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Go Web Server</title>
<style>
body { font-family: sans-serif; display: grid; place-content: center; height: 100vh; margin: 0; background-color: #f0f0f0; }
h1 { color: #007d9c; }
</style>
</head>
<body>
<h1>Hello from the Go Static Server!</h1>
</body>
</html>
📁 goserver/main.go
The Go code is incredibly simple, using only the standard library.
package main
import (
"log"
"net/http"
)
func main() {
// Create a file server handler to serve files out of the "./static" directory
fs := http.FileServer(http.Dir("./static"))
// Register the file server handler for all requests
http.Handle("/", fs)
log.Println("Starting static server on :8080")
// Start the server on port 8080
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
📁 goserver/Dockerfile
We'll use a multi-stage build to keep the final image extremely small and secure.
# ---- Build Stage ----
# Use the official Go image as a builder
FROM golang:1.22-alpine AS builder
# Set the working directory
WORKDIR /app
# Copy go.mod and go.sum to leverage Docker cache
# (We will create these files in the setup steps)
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build the Go application, creating a statically linked binary
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /server_binary .
# ---- Final Stage ----
# Use a minimal base image
FROM alpine:latest
# Copy only the compiled binary and the static assets from the builder stage
COPY --from=builder /server_binary /server_binary
COPY --from=builder /app/static /static
# Expose the port the server listens on
EXPOSE 8080
# The command to run when the container starts
CMD ["/server_binary"]
2. The Development Client (dev-client)
This container is your interactive prototyping environment.
📁 dev-client/Dockerfile
We'll start with the official Playwright image and add our tools.
# Use the official Playwright image which includes browsers, Node.js, and Python
FROM mcr.microsoft.com/playwright:v1.44.0-jammy
# Switch to root user to install packages
USER root
# Install developer tools: neovim and git
RUN apt-get update && apt-get install -y --no-install-recommends \
neovim \
git \
&& rm -rf /var/lib/apt/lists/*
# (Optional) Install Python Playwright bindings if you prefer Python
RUN pip install playwright
# Switch back to the non-privileged user for security
USER pwuser
📁 dev-client/test.js (Node.js example)
A sample script to demonstrate connectivity. Note how it uses http://goserver:8080.
const { chromium } = require('playwright');
(async () => {
console.log('Running Playwright test against the Go server...');
const browser = await chromium.launch();
const page = await browser.newPage();
// Docker Compose networking allows us to use the service name 'goserver' as the hostname
const url = 'http://goserver:8080';
console.log(`Navigating to ${url}`);
await page.goto(url);
// Verify the content
const headingText = await page.locator('h1').innerText();
console.log(`Found heading: "${headingText}"`);
if (headingText.includes("Hello from the Go Static Server!")) {
console.log("✅ Test Passed!");
} else {
console.error("❌ Test Failed!");
}
await browser.close();
})();
📁 dev-client/test.py (Python example)
The same test, but written in Python.
from playwright.sync_api import sync_playwright, expect
def run():
print("Running Playwright test against the Go server...")
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
# Docker Compose networking allows us to use the service name 'goserver' as the hostname
url = "http://goserver:8080"
print(f"Navigating to {url}")
page.goto(url)
# Verify the content
heading = page.locator("h1")
print(f"Found heading: \"{heading.inner_text()}\"")
expect(heading).to_contain_text("Hello from the Go Static Server!")
print("✅ Test Passed!")
browser.close()
if __name__ == "__main__":
run()
3. Docker Compose (docker-compose.yml)
This file orchestrates everything.
📁 docker-compose.yml
version: '3.8'
services:
goserver:
build:
context: ./goserver
container_name: goserver
ports:
# Expose on host port 8080 so you can see it in your browser
- "8080:8080"
restart: unless-stopped
devclient:
build:
context: ./dev-client
container_name: devclient
# depends_on ensures goserver is started before this container
depends_on:
- goserver
# Keep the container running for interactive use
stdin_open: true
tty: true
# Mount local directory into the container for live prototyping
volumes:
- ./dev-client:/home/pwuser/workspace
working_dir: /home/pwuser/workspace
How to Use
Step 1: Initialize Go Module
Before building, you need to initialize the Go module for the server. This is a one-time setup step.
# Navigate into the goserver directory
cd goserver
# Create the go.mod and go.sum files
go mod init goserver
go mod tidy
# Go back to the project root
cd ..
Step 2: Build and Run the Containers
From the project root (go-playwright-dev-env/), run:
# Build the images and start the containers in detached mode
docker-compose up -d --build
Step 3: Verify the Go Server
Open your web browser and navigate to http://localhost:8080. You should see the "Hello from the Go Static Server!" message.
Step 4: Start Prototyping!
Now, get an interactive shell inside your devclient container.
docker-compose exec devclient bash
You are now inside the development container! You'll find yourself in the /home/pwuser/workspace directory, which is synced with your local dev-client folder.
Run the Node.js Test:
# Inside the devclient container
node test.js
Run the Python Test:
# Inside the devclient container
python test.py
Both scripts should successfully connect to the goserver container and print a "Test Passed!" message. You can now use nvim to edit the files, git to manage versions, and run node or python scripts to your heart's content, all within this self-contained, networked environment.