Cloud Native 8 min read

How I Use Docker to Build a Fast, Portable Development Environment

This article explains how the author leverages Docker containers to create a lightweight, reproducible development environment, detailing the shortcomings of traditional script‑based setups, the Docker‑based workflow, helper tools, and steps for automating startup, all aimed at developers who love tinkering.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
How I Use Docker to Build a Fast, Portable Development Environment

Introduction

Docker is a lightweight container solution with low system intrusion and easy portability, making it ideal for complex business deployment and development environment setup. This article, originally published on OpsDev, shares how our company efficiently builds development environments using Docker.

Background

As a developer who enjoys experimenting, I like trying various environments and open‑source software while adhering to the principle of least privilege in Linux. Over the years I have worked with many stacks: CentOS 5‑7, Apache/Nginx, PHP 5.2‑7, Go (and soon C++), MySQL 5.1‑5.7, MariaDB, Memcache/Redis, Kafka, and NSQ.

Although we have dedicated deployment and operations staff, I prefer building these services myself to deepen my understanding.

Below I share how I efficiently set up my own development environment.

1. Preparation

I compile and deploy each open‑source software myself instead of using package managers, except for common dependencies like zlib, gcc, and make, which I install via yum install for convenience.

2. Traditional Approach

Previously I wrote scripts to compile and install each software. This caused several problems: scripts only work on the original OS version, break after OS upgrades, fail when software versions change, and require separate handling of conflicting library versions. Maintaining separate scripts for each distribution became tedious.

3. Docker Approach

My method with Docker:

Run each software in its own container, fixing the environment so a single build script suffices.

Mount source code into containers via data volumes.

Use --net=host for simple networking in development.

Store image creation and container startup scripts in a Git repository, abstracting a unified build process for easy onboarding of new software or machines.

Example: building an Nginx development environment.

Project repository: https://gitee.com/andals/docker-nginx

The README describes the required scripts and project structure.

Dockerfile Overview

The build framework:

Copy required packages (the pkg directory) into the image.

Copy build scripts into the image.

Execute the build script.

On container start, run init.sh to launch services.

The README lists the build and run commands; an example run is shown below.

4. Helper Tool: dockerbox

Interacting with containers can be cumbersome. To simplify tasks such as locating a container, entering it, or reloading services, I created dockerbox . It streamlines container operations. Usage details are at https://github.com/ligang1109/dockerbox .

5. Configure Auto‑Start

When using a virtual machine for the development environment, configuring services to start on boot is straightforward.

Conclusion

I hope fellow enthusiasts try this setup and share improvements. Keep tinkering!

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.

DockerAutomationDevOpsDevelopment Environment
360 Zhihui Cloud Developer
Written by

360 Zhihui Cloud Developer

360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.

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.