Cloud Native 14 min read

Docker Basics, Architecture, Commands, and Deployment Practices

This article introduces Docker as a leading container platform, explains its core concepts, architecture components, and common commands, and provides step‑by‑step tutorials for deploying a Node.js application and MongoDB using Dockerfile, Docker Compose, and related tools.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Docker Basics, Architecture, Commands, and Deployment Practices

Docker is a world‑leading software container platform built with Go, leveraging Linux kernel features such as cgroups, namespaces, and UnionFS to provide OS‑level virtualization, enabling isolated, portable containers for applications.

The basic architecture consists of a host machine running the Docker daemon, a Docker client that communicates with the daemon, and a Docker registry that stores images.

Key Docker components include:

Registry – stores and shares Docker images.

Docker image – a snapshot similar to a VM image, used to create containers.

Docker container – a runtime instance of an image, providing an isolated environment.

Data volume – a special directory for persistent data, shareable across containers.

Network – enables container communication via port mapping or linking.

Application scenario: Deploying a Node.js project

1. Create a .dockerignore file to exclude unnecessary files:

.git
node_modules

2. Write a Dockerfile (example):

FROM node:10.0
RUN mkdir -p /usr/src/nodejs/
WORKDIR /usr/src/nodejs/
COPY package.json /usr/src/app/package.json
RUN cd /usr/src/app/
RUN npm i
COPY . /usr/src/nodejs/
EXPOSE 3000
CMD npm start

Key Dockerfile directives: FROM – base image. RUN – execute commands, each creates a new layer. WORKDIR – set working directory. COPY – copy files, respecting .dockerignore. EXPOSE – expose container port. CMD – default command when container starts. ENV – set environment variables.

Build and run the image:

docker build -t dockerstudy .

docker run --name dockerstudycontainer -d -p 3000:3000 dockerstudy

Test the service with curl localhost:3000 and monitor resources using docker stats dockerstudycontainer.

Deploying MongoDB with Docker

Pull the MongoDB image and run a container:

docker pull mongo

docker run -p 27017:27017 -v /data/db --name docker_mongodb -d mongo

Explanation of parameters: -p – port mapping (host:container). -v – mount host directory to container for data persistence. --name – container name. -d – run in detached mode.

Connect to MongoDB using a GUI tool such as Robo 3T, ensuring the host firewall allows port 27017.

Docker Compose

Docker Compose allows defining multi‑container applications in a docker-compose.yml file, simplifying the orchestration of services like web servers, databases, and caches.

Advantages of Docker

Environment isolation and security.

Efficient resource utilization and cost savings.

Rapid delivery and agile deployment.

Portability across platforms and clouds.

Simplified update and management via Dockerfile.

Common Docker commands

Image commands

docker pull [image:tag]

docker images

docker rmi [image:tag]

docker tag [source] [target]

docker inspect [image]

docker search [keyword]

docker login

Container commands

docker ps -a

docker exec -ti <id> bash

docker run -ti --name <container> <image> bash

docker logs <container>

docker stop <container>

docker start <container>

docker rm <container>

docker commit <container> my_image:v1.0

By following the examples and commands above, readers can gain practical experience with Docker, understand its core concepts, and apply it to real‑world projects.

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.

DockerDevOpsNode.jscontainerizationDockerfileMongoDBDocker Compose
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.