Cloud Native 10 min read

Building a Container‑Based Development Environment with Docker and VSCode Remote Development

This guide explains how to create a flexible, version‑controlled development environment on Linux using Docker containers and VSCode's Remote Development extensions, covering image construction, VSCode configuration, container user settings, and useful command‑line tools for an optimized workflow.

Fulu Network R&D Team
Fulu Network R&D Team
Fulu Network R&D Team
Building a Container‑Based Development Environment with Docker and VSCode Remote Development

Introduction: Linux dominates server environments, yet many developers still use Windows, leading to platform‑specific issues such as CRLF line endings and cumbersome software installation. Using containers can provide a portable, reusable, and version‑controlled development environment that works seamlessly across operating systems.

Prerequisites: Docker (Docker Desktop on Windows) and a code editor such as VSCode or the JetBrains suite.

Container‑based development is essentially remote development. VSCode runs directly inside the container, while JetBrains syncs files via FTP/SFTP. This article demonstrates the VSCode approach.

1. Build the Docker Image

Select a familiar Linux distribution (the author prefers Arch Linux) and create a Dockerfile that installs the required tools and configures mirrors. Example Dockerfile:

FROM docker.io/library/archlinux:latest

RUN sed -i '1i Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch' /etc/pacman.d/mirrorlist \
    && sed -i '1i Server = https://mirrors.tencent.com/archlinux/$repo/os/$arch' /etc/pacman.d/mirrorlist \
    && sed -i '$i [archlinuxcn]' /etc/pacman.conf \
    && sed -i '$i SigLevel = TrustAll' /etc/pacman.conf \
    && sed -i '$i Server = https://repo.archlinuxcn.org/$arch' /etc/pacman.conf \
    && sed -i -r 's/^NoExtract\s*=\s*.*/# \0/g' /etc/pacman.conf \
    && pacman -Syyu --noconfirm \
    && pacman -Sy --noconfirm archlinuxcn-keyring && pacman -Su --noconfirm\
    && pacman -Syy --noconfirm git vim neovim zsh oh-my-zsh-git jdk-openjdk jdk8-openjdk jdk11-openjdk \
    maven yay zsh python3 go nodejs npm yarn tmux python2 zsh-autosuggestions zsh-syntax-highlighting \
    zsh-theme-powerlevel10k ranger python-pip python-neovim wl-clipboard fzf ripgrep man-db \
    gcc clang base-devel wqy-zenhei noto-fonts-cjk wget unzip thefuck \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && pacman -Scc --noconfirm \
    && rm -rf /var/lib/pacman/sync/* /var/cache/pacman/pkg/* \
    && echo "" > /var/log/pacman.log

Build the image with:

docker build -t arch-test .

The resulting image contains a ready‑to‑use development environment.

2. Configure VSCode

Install the Remote Development Pack extension and the Docker extension. The Remote Development extension allows VSCode to run inside the container, so the code never resides on the host machine.

If the Docker extension is installed, you can manage containers directly from the sidebar and attach VSCode to a running container. Otherwise, open the command palette ( Ctrl+Shift+P ) and select “Remote‑Containers: Attach to Running Container”.

After attachment, VSCode will prompt you to reinstall extensions inside the container.

3. Container Configuration

VSCode connects as the root user by default, but you can configure a non‑root user. Open the command palette, run “Remote‑Container: Open Configuration File”, and edit the JSON configuration, for example:

{
  // Default folder opened when VSCode attaches
  "workspaceFolder": "/path/to/code/in/container/here",

  // Extensions automatically installed in the container
  "extensions": ["dbaeumer.vscode-eslint"],

  // Settings that override the host's settings.json
  "settings": {
    "terminal.integrated.shell.linux": "/bin/zsh"
  },

  // Ports automatically forwarded to the host
  "forwardPorts": [8000],

  // User to use when connecting (default is root)
  "remoteUser": "vscode",

  // Environment variables inherited by VSCode processes
  "remoteEnv": { "MY_VARIABLE": "some-value" }
}

Create the user inside the container (or add it in the Dockerfile) with:

useradd -d /home/vscode -m vscode && passwd vscode

VSCode will forward exposed ports (e.g., localhost:8000 ) automatically, or you can specify them via the forwardPorts setting.

4. Further Optimizations

Beyond a basic environment, the author recommends several command‑line tools to enhance productivity:

Replace the default Bash with zsh plus oh‑my‑zsh , powerlevel10k , zsh‑autosuggestions , and zsh‑syntax‑highlighting .

Use tmux (and oh‑my‑tmux ) for terminal multiplexing.

Leverage neovim , ranger , fzf , and ripgrep for in‑terminal editing and fuzzy searching.

Install patched fonts (e.g., nerd‑fonts ) for better UI rendering.

Map host directories into the container to keep code secure and persistent.

The author maintains personal configuration files (vim, zsh, tmux) on GitHub Gist and plans to write a dedicated article about them.

Conclusion

By building a Docker‑based development container, you gain version‑controlled, portable environments that eliminate the inconsistencies between Windows and Linux, allowing seamless migration to new machines simply by moving the image.

References:

1. VSCode Remote Development Overview 2. Docker Desktop Documentation

DockerDevOpsLinuxVSCodeRemote Developmentdevcontainer
Fulu Network R&D Team
Written by

Fulu Network R&D Team

Providing technical literature sharing for Fulu Holdings' tech elite, promoting its technologies through experience summaries, technology consolidation, and innovation sharing.

0 followers
Reader feedback

How this landed with the community

login 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.