Cloud Native 14 min read

How Docker Simplifies Private Deployment: A Complete Step‑by‑Step Guide

This article explains the challenges of traditional private deployment, introduces Docker container technology and its benefits, and provides detailed instructions—including Dockerfile creation, image building, network setup, container linking, image export/import, and container startup—to dramatically reduce deployment time and effort.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
How Docker Simplifies Private Deployment: A Complete Step‑by‑Step Guide

Overview

Private deployments often suffer from offline npm package installation, environment drift between testing and production, repeated machine configuration, and the need for constant supervision. Docker container deployment solves these problems by encapsulating the application and its dependencies in a portable, isolated image.

Docker fundamentals

Docker is a lightweight virtualization technology that packages an application with its runtime environment. Its main characteristics are:

Lightweight: no extra hypervisor layer, low resource overhead.

Portable: identical runtime across platforms.

Isolated: containers run independently, improving security and stability.

Versionable: images can be tagged and rolled back.

Basic concepts

Image

An image is a read‑only filesystem snapshot (e.g., ubuntu:16.04) that serves as the template for containers.

Container

A container is a runtime instance of an image, analogous to an object created from a class.

Repository

A repository stores images, similar to an npm registry.

Building an image

Create a Dockerfile that defines each build step as a layer. Example:

FROM node:lts-alpine AS builder
WORKDIR /home/node/app
COPY front .
COPY .yarnrc .
RUN yarn --registry=https://registry.npm.taobao.org && yarn build

FROM nginx:stable-alpine
WORKDIR /usr/share/nginx/html
COPY --from=builder /home/node/app/dist .
COPY front/nginx.conf /etc/nginx/conf.d/default.conf
COPY front/ssl /etc/nginx/ssl
EXPOSE 80 443

The FROM instruction specifies the base image and must be the first line. RUN executes commands during the build, either in shell form ( RUN <command>) or exec form ( RUN ["executable", "arg1"]).

Build the image with:

docker build -t nginx:v3 .

Docker network and container linking

Containers are isolated; to enable communication, create a custom bridge network. docker network create -d bridge my-net Run containers on the network:

docker run -it --rm --name busybox1 --network my-net busybox sh
docker run -it --rm --name busybox2 --network my-net busybox sh

Use ping inside one container to verify connectivity to the other.

Exporting and importing images

Export image

docker save -o images.tar postgres:9.6 mongo:3.4

Export container

docker export -o postgres-export.tar postgres

Key differences: docker save saves one or more images; docker export saves a container’s filesystem. docker load restores an image tar; docker import restores a container tar (both produce an image).

Import commands:

docker load -i /path/to/fedora-latest.tar
docker import /path/to/latest.tar

Running containers

Assuming the images my-server and my-front have been loaded:

docker network create -d bridge my-net

docker run -d -p 8360:8360 --network my-net --network-alias myserver my-server

docker run -d -p 8080:80 --network my-net --network-alias myfront my-front

Practical deployment steps

Install Docker on the target host.

Create a bridge network: docker network create -d bridge my-net.

Transfer image tar files (e.g., my-front.tar, my-server.tar) to the host.

Load the images: docker load -i my-front.tar and docker load -i my-server.tar.

Start the server container:

docker run -d -p 8360:8360 --network my-net --network-alias myserver my-server

.

Start the frontend container:

docker run -d -p 8080:80 --network my-net --network-alias myfront my-front

.

These commands typically complete a private deployment in about ten minutes, guaranteeing identical environments for testing and production.

References

Docker official documentation.

Detailed comparison of docker save and docker export.

"Docker – From Beginner to Practice".

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDockerfileDocker ComposePrivate DeploymentContainer DeploymentImage ExportDocker Network
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.