跪拜 Guibai
← All articles
Backend · Docker · Containers

Docker Deployment, End to End: Building, Pushing, and Running Containers with Harbor

By Dragon_xjy ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This is a concrete reference for teams that need a private image registry and production rollback capability, showing how to bridge the gap between building on a Mac and running on an amd64 server, and how to keep secrets out of images while still passing configuration at runtime.

Summary

A practical walkthrough covers the whole Docker deployment chain: prepare a Linux server with firewall rules, install the BT panel and Harbor image registry, then build and push a frontend image using buildx with the right platform flag. The two-stage Dockerfile compiles a Vue app with Node and serves the static output through Nginx, with a proxy configuration that handles API streaming, uploads, and Vue Router fallback.

The backend follows a similar path but keeps secrets out of the image by loading them from a server-side .env file via --env-file. The guide also details how to make Docker accept an HTTP-only Harbor registry on an intranet, how to use host.docker.internal to reach host services from containers, and why production images should be tagged with commit or date versions instead of latest. A final rollback procedure relies on pulling an older image from Harbor or rebuilding from old code.

Takeaways
— Use buildx with --platform linux/amd64 so images built on Apple Silicon Macs run on standard Linux servers.
— A two-stage frontend Dockerfile separates the Node build environment from the Nginx runtime, reducing final image size.
— Harbor on port 8005 stores images and keeps historical versions, enabling rollback to a known-good tag.
— For an HTTP-only registry in an intranet, add "insecure-registries" to Docker daemon config on both Docker Desktop and the server.
— Backend secrets like database passwords go in a separate env file on the server, passed at runtime with --env-file, not baked into the image.
— Set --restart unless-stopped so containers recover automatically after a server reboot.
— Version images with a commit or date string (e.g., 2026.11.25-a1b2c3) rather than latest for precise rollback.
— The Nginx proxy config disables buffering for /api/ to support agent streaming responses and sets a 600s read timeout for long model inference.
Conclusions

The guide treats HTTPS for Harbor as mandatory in production, while demoting HTTP to an isolated intranet experiment, a sensible stance given plaintext credential transmission.

Rollback is framed as the primary safety net: start an old image if the new version fails, and rebuild from old code only when no old image exists, making persistent image versioning a core operational habit.

Opening only required ports and using host.docker.internal for container-to-host access reduces the attack surface and simplifies service wiring without extra network configuration.

The explicit read timeout of 600 seconds and streaming-friendly proxy settings reflect a real-world need to support AI agent backends, not just static web apps.

Concepts & terms
Harbor
An open-source container image registry that stores Docker images by version, allowing multiple machines to pull the same image and keeping history for rollbacks.
buildx
A Docker CLI plugin that supports multi-platform builds, letting you build a Linux/amd64 image from a developer machine such as an Apple Silicon Mac.
insecure-registries
A Docker daemon configuration that tells Docker to accept an HTTP-only registry address without TLS, useful for intranet testing but unsuitable for public networks.
host.docker.internal
A hostname that resolves to the host machine from inside a container, enabled on Linux with --add-host=host.docker.internal:host-gateway, letting containers reach services running on the host.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗