<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kai wen ng</title>
    <description>The latest articles on DEV Community by kai wen ng (@kai-wen-the-parrot).</description>
    <link>https://dev.to/kai-wen-the-parrot</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4045609%2F22bfd08f-f10d-4fa8-89ee-0f896810f5d0.jpeg</url>
      <title>DEV Community: kai wen ng</title>
      <link>https://dev.to/kai-wen-the-parrot</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kai-wen-the-parrot"/>
    <language>en</language>
    <item>
      <title>Docker Storage Mounts and Best Practices</title>
      <dc:creator>kai wen ng</dc:creator>
      <pubDate>Sat, 25 Jul 2026 04:46:00 +0000</pubDate>
      <link>https://dev.to/kai-wen-the-parrot/docker-storage-mounts-and-best-practices-4eeg</link>
      <guid>https://dev.to/kai-wen-the-parrot/docker-storage-mounts-and-best-practices-4eeg</guid>
      <description>&lt;p&gt;To avoid bloated Docker images and containers, it is a best practice to store persistent data outside the container's writable layer by using &lt;strong&gt;storage mounts&lt;/strong&gt;.&lt;br&gt;
Mounting allows a Docker container to access files from external storage locations. Depending on the mount type, the container can read, write, and sometimes execute files without storing them inside the container image.&lt;br&gt;
Docker provides three main types of mounts:&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Docker Volume Mounts
&lt;/h2&gt;

&lt;p&gt;Docker volumes are the recommended method for storing persistent application data.&lt;br&gt;
Volumes are managed directly by Docker and are independent of the container lifecycle. They can be listed using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A volume can be attached to multiple containers, allowing containers to share persistent data without recreating or copying data between containers.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-v&lt;/span&gt; my_volume:/data my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managed by Docker&lt;/li&gt;
&lt;li&gt;Portable across containers&lt;/li&gt;
&lt;li&gt;Survives container removal&lt;/li&gt;
&lt;li&gt;Better isolation compared to directly mounting host directories&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Bind Mounts (Host File System Mounts)
&lt;/h2&gt;

&lt;p&gt;A bind mount maps a directory or file from the host machine directly into the container.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-v&lt;/span&gt; /host/directory:/mnt my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The container can directly access the host directory through &lt;code&gt;/mnt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allows direct access to host files&lt;/li&gt;
&lt;li&gt;Useful for development environments&lt;/li&gt;
&lt;li&gt;Enables live code updates without rebuilding images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Common use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mounting source code during development&lt;/li&gt;
&lt;li&gt;Sharing configuration files&lt;/li&gt;
&lt;li&gt;Accessing hardware devices or system resources&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. tmpfs Mounts (Linux Only)
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;tmpfs&lt;/code&gt; mounts store data directly in the host machine's RAM instead of disk storage.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--tmpfs&lt;/span&gt; /tmp my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the data exists only in memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No data is written to the Docker writable layer&lt;/li&gt;
&lt;li&gt;Data disappears when the container stops&lt;/li&gt;
&lt;li&gt;Disk persistence is not possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes tmpfs suitable for temporary or sensitive data, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Credentials&lt;/li&gt;
&lt;li&gt;Temporary files&lt;/li&gt;
&lt;li&gt;Runtime secrets&lt;/li&gt;
&lt;li&gt;Cryptographic keys&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster access due to RAM storage&lt;/li&gt;
&lt;li&gt;Reduces disk writes&lt;/li&gt;
&lt;li&gt;Prevents sensitive data from being stored permanently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Available mainly on Linux systems&lt;/li&gt;
&lt;li&gt;Data is lost after container termination&lt;/li&gt;
&lt;li&gt;Limited by available memory&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Using the appropriate mount type helps keep Docker images lightweight, improves data management, and provides better control over persistence and security.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
      <category>devops</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Docker as Cross Compilation Platform</title>
      <dc:creator>kai wen ng</dc:creator>
      <pubDate>Fri, 24 Jul 2026 12:58:26 +0000</pubDate>
      <link>https://dev.to/kai-wen-the-parrot/docker-as-cross-compilation-platform-917</link>
      <guid>https://dev.to/kai-wen-the-parrot/docker-as-cross-compilation-platform-917</guid>
      <description>&lt;p&gt;Having various dependencies when setting up a software development environment can be frustrating, especially when dealing with legacy C/C++ systems that require specific compiler versions, libraries, and outdated operating systems.&lt;/p&gt;

&lt;p&gt;Using Docker as a cross-compilation and development environment can significantly simplify this process.&lt;/p&gt;

&lt;p&gt;The main advantages are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Isolation of dependencies&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Docker provides an isolated environment where required compilers, libraries, headers, and system packages can be installed without affecting the host machine. This avoids dependency conflicts and keeps the existing development environment clean.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Reproducible legacy environments&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Docker allows developers to recreate older Linux distributions and software environments that match production systems. For example, an Ubuntu 20.04 container can be used to build applications that depend on older libraries or toolchains, even if the host machine is running a newer operating system.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Explicit environment definition&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By defining dependencies through Dockerfiles and container configurations, the required build environment becomes clear, reproducible, and easier to maintain. New developers can recreate the same environment without manually installing every dependency.&lt;/p&gt;




&lt;p&gt;With this approach, I created a lightweight Docker-based compilation platform for a legacy CGI C/C++ system.&lt;/p&gt;

&lt;p&gt;The first step was creating a minimal Docker image based on &lt;strong&gt;Ubuntu 20.04&lt;/strong&gt;. Required header files, compilers, development tools, and libraries were then installed inside the container.&lt;/p&gt;

&lt;p&gt;Initially, I considered copying the entire source code and website files into the Docker image and compiling everything during container runtime. However, this approach introduced several issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Docker image became unnecessarily large.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every source code change required rebuilding the image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The development cycle became slower due to repeated compilation and image creation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead, I separated the &lt;strong&gt;development environment&lt;/strong&gt; from the &lt;strong&gt;source code&lt;/strong&gt; by mounting the project files into the running container.&lt;/p&gt;

&lt;p&gt;The workflow became:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Build the Docker image containing only the required compilation environment and dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mount the source code and website resources into the container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the running container:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;container_name&amp;gt; /bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the mounted project directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the required compilation commands:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or any other installation/build command required by the project.&lt;/p&gt;

&lt;p&gt;With this setup, the host machine does not need to contain the legacy dependencies or libraries. The Docker container provides the complete build environment, while the source code remains directly accessible from the host through volume mounting.&lt;/p&gt;

&lt;p&gt;This provides several practical benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Source code changes are immediately reflected inside the container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No container rebuild is required after every code modification.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No Docker image recompilation is needed during development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The legacy CGI application can be compiled and updated quickly while maintaining a clean host environment.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach effectively turns Docker into a portable legacy development workstation, allowing old C/C++ systems to be maintained and modified using modern development workflows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1w0uammfyn27fgwnnonp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1w0uammfyn27fgwnnonp.jpg" alt=" " width="407" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>c</category>
      <category>development</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
