Docker Basics: From Theory to Practical Deployment
This article introduces Docker by explaining container fundamentals, comparing virtual machines and containers, detailing core Docker concepts, guiding readers through installation, building a Vue project image with Nginx, running and publishing the container, and offering best‑practice tips for efficient containerization.
In the era of rich web applications, containerization bridges the gap between complex deployment requirements and lightweight, portable execution.
Story analogy: Building a house, copying it as an "image", and moving it to the sea illustrates how Docker images enable rapid replication and scaling of projects.
Virtual Machine vs. Container: Virtual machines emulate full hardware and are heavyweight, while containers virtualize only the OS layer, offering higher resource utilization, faster startup, and easier scaling.
Core Docker concepts: Image, Container, Repository. Docker uses Linux kernel features (cgroups, namespaces) to isolate processes, and on non‑Linux hosts it runs a lightweight VM to provide the necessary kernel.
Installation: On macOS, install via Homebrew with brew cask install docker or download the desktop client. Verify installation with docker -v and configure registry mirrors in the daemon JSON.
Quick start with a Vue project: Create a Vue app ( vue create docker-demo ), build it ( yarn build ), and note that the dist folder contains static assets.
Prepare Nginx: Pull the official image ( docker pull nginx ) and create a custom default.conf with a simple server block serving files from /usr/share/nginx/html .
Dockerfile:
FROM nginx
COPY dist/ /usr/share/nginx/html/
COPY default.conf /etc/nginx/conf.d/default.confBuild the image with docker build -t jartto-docker-demo . , producing a ~133 MB image.
Run the container: docker run -d -p 3000:80 --name docker-vue jartto-docker-demo . Access the app at http://localhost:3000 or via curl -v -i localhost:3000 .
Publish the image: Log in to Docker Hub ( docker login ), tag the image ( docker tag jartto-docker-demo username/jartto-docker-demo:latest ), and push it ( docker push username/jartto-docker-demo:latest ).
Best practices: Clearly define required base images, keep Dockerfile steps minimal, pin versions, and document the build process for reproducibility.
Conclusion: Mastering Docker opens the door to modern cloud‑native workflows, and the skills extend to orchestration tools like Kubernetes, Service Mesh, and beyond.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.