无需Docker Hub,如何在DigitalOcean用Docker部署应用至容器OS?
docker export + SSH/SFTP the preferred way to deploy Docker apps to DigitalOcean (CoreOS/RancherOS)? Great question—let’s unpack this clearly, since avoiding third-party registries like Docker Hub is a totally valid goal.
First, let’s get straight: using docker export is not the preferred approach, and here’s why:
docker exportcreates a flat filesystem snapshot of a running or stopped container, not a Docker image. This means you lose all the critical metadata that makes Docker images reusable and maintainable: environment variables, exposed ports, default startup commands, volume mounts, and the layered filesystem structure.- When you transfer this snapshot to your Droplet, you’ll have to manually reconstruct the container configuration every time (e.g., setting ports, env vars, entrypoints) instead of just running the pre-configured image.
- Updates become inefficient: since there’s no layered structure, you’ll have to transfer the entire filesystem snapshot every time you make a change, instead of only the modified layers.
Better Alternatives (No Third-Party Registries Required)
1. Use docker save + docker load (Simplest for Small-Scale Deployments)
This method preserves your full Docker image (including all metadata and layers) without relying on external registries:
- On your local machine, save the image to a tar file:
docker save -o my-app-image.tar my-app:latest - Transfer the tar file to your DigitalOcean Droplet via SSH/SCP:
scp my-app-image.tar core@your-droplet-ip:/home/core/ - On the Droplet (CoreOS/RancherOS both have Docker pre-installed), load the image:
docker load -i my-app-image.tar - Now you can run the container exactly as you would with an image from Docker Hub:
docker run -d --name my-app -p 80:80 my-app:latest
2. Host a Private Docker Registry (Best for Scaling/Frequent Updates)
If you have multiple Droplets or plan to update your app regularly, hosting your own private registry on DigitalOcean is a far more scalable approach. It works just like Docker Hub, but it’s entirely under your control:
- On your Droplet, start a private registry container (this uses the official
registryimage):docker run -d -p 5000:5000 --restart=always --name private-registry registry:2 - On your local machine, tag your image to point to your private registry:
docker tag my-app:latest your-droplet-ip:5000/my-app:latest - Push the image to your private registry:
docker push your-droplet-ip:5000/my-app:latest - On any Droplet, pull the image directly from your registry:
docker pull your-droplet-ip:5000/my-app:latest
This method only transfers modified image layers during updates, saves you from manually transferring tar files, and keeps your workflow aligned with standard Docker practices.
Final Notes for CoreOS/RancherOS
Both of these alternatives work seamlessly with CoreOS and RancherOS—they’re designed to run Docker containers natively, so you won’t hit any compatibility issues. RancherOS even has built-in support for managing registries if you want to take it a step further.
So to wrap up: skip docker export—use docker save/docker load for one-off or small deployments, or set up a private registry for long-term, scalable workflows.
内容的提问来源于stack exchange,提问作者user457586

