Here's a Docker Compose setup that meets your requirements. This setup includes a Go server to host static files and a development container with Playwright, Neovim, Git, Node.js, and Python for prototyping:
Project Directory Structure
my-project/
├── go-server/
│ ├── Dockerfile
│ └── main.go
├── static/
│ └── index.html
├── dev-container/
│ └── Dockerfile
└── docker-compose.yml
Step 1: Go Server Setup
go-server/Dockerfile
# Build the Go executable
FROM golang:1.20 AS builder
WORKDIR /app
COPY main.go .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main .
# Final image for serving static files
FROM alpine:3.18
COPY --from=builder /app/main /app/main
EXPOSE 8080
CMD ["/app/main"]
go-server/main.go
package main
import (
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("/app/static"))
http.Handle("/", fs)
log.Fatal(http.ListenAndServe(":8080", nil))
}
Step 2: Development Container Setup
dev-container/Dockerfile
# Use Node base image for Playwright
FROM node:18-bullseye
# Install system dependencies
RUN apt-get update && apt-get install -y \
neovim \
git \
python3 \
python3-pip \
&& apt-get clean
# Install Playwright and dependencies
RUN npm install -g playwright
RUN playwright install
# Create non-root user
RUN useradd -m -u 1000 dev
USER dev
WORKDIR /app
CMD ["bash"]
Step 3: Docker Compose Configuration
docker-compose.yml
version: '3.8'
services:
go-server:
build:
context: ./go-server
dockerfile: Dockerfile
ports:
- "8080:8080"
volumes:
- ./static:/app/static
networks:
- devnet
dev:
build:
context: ./dev-container
dockerfile: Dockerfile
volumes:
- ./static:/app/static # Shared static files directory
- ./dev-container:/app # Optional: For dev project files
working_dir: /app
networks:
- devnet
stdin_open: true
tty: true
environment:
- NODE_ENV=development
networks:
devnet:
driver: bridge
Step 4: Static Files
static/index.html (Sample)
<!DOCTYPE html>
<html>
<head><title>Go Server</title></head>
<body>
<h1>Hello from Go Server!</h1>
<script>
document.write(new Date())
</script>
</body>
</html>
Usage Instructions
-
Start Services
docker-compose up -d
-
Access the Go Server
- Browser:
http://localhost:8080
- From the dev container:
http://go-server:8080
-
Enter the Dev Container
docker-compose exec dev bash
-
Development Workflow
- Edit files in
./static (changes will be reflected instantly)
- Use Neovim:
nvim index.html
- Run Playwright tests:
// playwright.test.js
const { chromium } = require('playwright');
test('test go server', async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('http://go-server:8080');
await expect(page).toHaveTitle('Go Server');
await browser.close();
});
npx playwright test playwright.test.js
-
Python/Node Prototyping
Key Features
- Shared Static Files: Both containers share the
./static directory for live updates
- Network Communication: The
devnet network allows the dev container to access the Go server via http://go-server:8080
- Full Development Environment: Includes:
- Neovim for coding
- Git for version control
- Playwright for browser automation
- Node.js and Python for scripting
To stop the services:
docker-compose down
This setup provides a fully contained environment for rapid prototyping with both frontend (Go server) and backend (Node/Python) development capabilities.