Docker Deployment, End to End: Building, Pushing, and Running Containers with Harbor
Docker deployment can be summarized as a chain: prepare the server → configure the image registry → build the image → push the image → pull on the server → start the container → verify the service.
This post uses a frontend container and a backend container as examples, demonstrating the complete flow from image building to deployment verification. Replace the IP, domain, account, and key in the commands with your own values.
1. Prepare the server
Rent a server and open ports
Start with a Linux cloud server, then open the required ports in both the cloud platform's security group and the server firewall. Do not disable the entire firewall for convenience—only open the ports you actually use.
View the server IP:
Allow ports to access your instance
Common port uses:
| Port | Use | Recommendation |
|---|---|---|
| 22 | SSH login | Allow only trusted IPs |
| 80 / 443 | Website entry | Open to the public |
| 8005 | Harbor image registry | Restrict to office network or VPN |
| 8088 | Frontend test entry | Production can use 80/443 reverse proxy |
| 8000 | Backend API | Keep off the public network if possible |
Install Bao Ta (BT Panel)
https://www.bt.cn/new/download.html
Open the BT panel official website, copy the Linux installation command for the current version, and run it in the server terminal. The installation command changes with versions—do not keep using an old command for a long time after publishing; always use the official current command.
A common installation example:
if [ -f /usr/bin/curl ];then curl -sSO https://download.bt.cn/install/install_panel.sh;else wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh;fi;bash install_panel.sh rU2tN9mZ
After installation completes, the terminal displays the BT panel access address, account, and password. Save these first, then log into the management panel.
Remember the account and password shown by the BT panel.
When logging into the BT panel, use the address, account, and password shown after installation.
2. Install and configure Harbor
Install Docker management tools or Harbor from the BT panel software store. Harbor stores images so both the development machine and the server can pull the same image by version.
After installation, view the Harbor address in the management page, for example:
服务器IP:8005
Harbor's default account is usually admin, and the initial password is as shown on the installation page. Change the password immediately after login; do not use the default password in production.
Click to open, and you can see the access path of the Harbor management backend, then log in with the account above.
3. Handle image registry connection
Recommended: use HTTPS
Configure a domain and TLS certificate for Harbor in production, then log in directly:
docker login <Harbor域名>:8005
Intranet testing: HTTP registry
If Harbor is temporarily HTTP-only, Docker may report:
http: server gave HTTP response to HTTPS client
This means Docker is accessing via HTTPS, but Harbor returns HTTP. For intranet testing, add this to both Docker Desktop and the server's Docker daemon:
{
"insecure-registries": [
"服务器IP:8005"
]
}
Add this in Docker Desktop.
On the server, modify /etc/docker/daemon.json; in Docker Desktop, modify the Docker Engine configuration. After saving, restart Docker:
sudo systemctl restart docker
HTTP registries transmit credentials in plain text, so they are only suitable for isolated intranet experiments; use HTTPS in public environments.
Login and connectivity check:
docker login 服务器IP:8005
If login times out, first check DNS, ports, and the Docker service:
getent hosts 服务器IP
curl -I --connect-timeout 10 http://服务器IP:8005/v2/
docker version
A 401 Unauthorized response usually means the registry network is connected; only the interface requires login.
4. Build and push the frontend image
The frontend image uses a "two-stage" build: the first stage compiles the frontend source with Node, the second stage serves the dist static files with Nginx.
The frontend Dockerfile's core structure:
# Specify the base image address; can be replaced with another registry via the same parameter during build.
ARG NODE_IMAGE=public.ecr.aws/docker/library/node:22-alpine
ARG NGINX_IMAGE=public.ecr.aws/docker/library/nginx:1.27-alpine
# Compilation stage uses the local architecture to avoid emulating AMD64 on a Mac for installing dependencies and compiling the frontend.
FROM --platform=$BUILDPLATFORM ${NODE_IMAGE} AS build
WORKDIR /app
ARG BUILD_MODE=production
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build -- --mode ${BUILD_MODE}
# Runtime stage uses the platform specified in the build command, generating an Nginx image for the server to run.
FROM ${NGINX_IMAGE}
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
Execute the build and push:
docker buildx build \
--platform linux/amd64 \
--build-arg BUILD_MODE=test \
-t 服务器IP:8005/frontend/web:latest \
--push \
.
Parameter explanations:
--platform linux/amd64: builds the image for common server architecture, avoiding the issue where an image built on an Apple Silicon Mac cannot run on an amd64 server.--build-arg BUILD_MODE=test: selects the frontend build environment; change toproductionfor production releases.-t: sets the registry, image name, and version tag.--push: pushes directly to Harbor after building.
For production, replace latest with a commit number or date version, such as 2026.11.25-a1b2c3, so you can accurately roll back when problems occur.
5. Deploy the frontend container
First, let Nginx know where the backend is. This uses the approach of "frontend container accessing the host's 8000 port":
# Access the backend through the host's 8000 port; modify if the backend address is different.
upstream api_backend {
server host.docker.internal:8000;
}
server {
# The container listens on port 80 internally; the page files are copied to this directory by the Dockerfile.
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# Pages allow uploading files up to 100 MiB; extra space is reserved for the upload form.
client_max_body_size 110m;
# Pass the browser's access source to the backend for logging and request address identification.
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "";
location /api/ {
# No trailing slash on the address, so the backend still receives the path containing /api/.
proxy_pass http://api_backend;
# Forward responses to the browser as soon as the backend replies; streaming text from agents does not need to wait for the whole response.
proxy_buffering off;
proxy_cache off;
# Wait at most 10 minutes between two reads of backend data, compatible with longer model processing times.
proxy_read_timeout 600s;
}
location /uploads/ {
# Uploaded files are provided by the backend; image preview and download are also forwarded to the same service.
proxy_pass http://api_backend;
}
location / {
# Return the homepage if a file does not exist, letting Vue Router handle page addresses like /agent.
try_files $uri $uri/ /index.html;
}
}
On the server, pull and start the frontend:
docker run -d \
--name ai-vue \
--restart unless-stopped \
-p 8088:80 \
--add-host=host.docker.internal:host-gateway \
服务器ip/frontend/ai-vue:latest
Access:
http://服务器IP:8088
6. Build and deploy the backend
The backend's database password and similar content should not be written into the image; put them separately in a server-side configuration file, such as /ai-fastapi.env:
DATABASE_URL=替换为真实数据库地址
In the backend project directory, build and push:
docker buildx build \
--platform linux/amd64 \
-t 服务器ip/backend/ai-fastapi:latest \
--push \
.
On the server, pull and start:
docker run -d \
--name ai-fastapi \
--restart unless-stopped \
-p 8000:8000 \
--add-host=host.docker.internal:host-gateway \
--env-file /root/ai-fastapi.env \
43.139.77.242:8005/backend/ai-fastapi:latest
Key parameters:
--env-file: passes the server configuration into the container; keys do not enter the image.-p 8000:8000: maps host 8000 to backend container 8000.--add-host=host.docker.internal:host-gateway: allows the backend container to access services on the host; delete this if not needed.--restart unless-stopped: automatically restores the container after a server reboot.
Summary
Suggest summarizing into five things for deployment flow:
- Dockerfile: defines how the image is built.
- buildx: builds the image for the server architecture and tags it with a version number.
- Harbor: stores and distributes images, retaining historical versions.
- docker pull + docker run: pulls the specified version of the image and starts the container.
- BT panel + logs/curl: view container status, check logs, and verify the service. If the new version has issues, prioritize starting an older image from Harbor; use logs/curl to verify the service.
Version rollback: if an old image exists, pull that version and restart; if not, rebuild the image from old code and redeploy.
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
I used AI to make a full-stack mini-program: specifically for couples quarrels and family discord [melon-eating crowd]