Custom dev container in VSCode

When developing with docker container, developers may need local packages that anren’t required in development, staging, or production environments. For exemple, team member may prefer different shells like zsh ou fish. This guide tutorial explains how to install packages and configure local containers in VSCode without modifyng the project’s Dockerfile.

💡
If you don’t have VSCode running inside a Docker container yet, see this tutorial before continuing.

How install packages only at local container

In file .devcontainer/devcontainer.json change the line postCreateComand.

"postCreateCommand": "chmod +x ./local-entrypoint.sh && ./local-entrypoint.sh",

The command above will execute local-entrypoint.sh after starting local container in vscode. Therefore, create the local-entrypoint.sh at root directory with following content:

#!/bin/sh
set -e

echo "🔄 Updating local system"
apt update && apt install -y curl tree zsh git

echo "🚀 Installing oh-my-zsh..."
yes | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
chsh -s /bin/zsh

echo "⚙️ Setting up Git configs..."
git config --global --add safe.directory /workspaces/$GIT_VERSIONED_DIRECTORY_NAME
git config --global user.name "$GIT_USER_NAME"
git config --global user.email "$GIT_USER_EMAIL"

echo "📋 System info:"
cat /etc/os-release

echo "✅ Setup complete!"

exec "$@"

The script above installs packages (curl, tree, zsh, git, oh-my-zsh) and configures git using environment variables:

  • GIT_VERSIONED_DIRECTORY_NAME - Directory name for Git safe.directory

  • GIT_USER_NAME - Git user name

  • GIT_USER_EMAIL - Git user email

💡
Insert local-entrypoint.sh at .gitignore file.

Customize vscode terminal, theme and extensions

In file .devcontainer/devcontainer.json change the line customizations:

:
"customizations": {
        "vscode": {
            "settings": {
                "terminal.integrated.profiles.linux": {
                    "zsh": {
                        "path": "/bin/zsh"
                    }
                },
                "terminal.integrated.defaultProfile.linux": "zsh",
                "workbench.colorTheme": "Visual Studio Light",
            },
            "extensions": [
                "ms-python.python",
                "ms-azuretools.vscode-docker",
                "eamodio.gitlens",
                "ritwickdey.liveserver"
            ]
        }
    }
10
Subscribe to my newsletter

Read articles from Eduardo Basílio directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Eduardo Basílio
Eduardo Basílio

Software Development Professional with expertise in systems architecture and cloud-native technologies. Specialized in Python and its ecosystem (Flask, FastAPI, Django), with solid experience in containerization via Docker and AWS infrastructure. Active practitioner of agile methodologies (Scrum) and test-driven development (TDD). I stand out for clear communication, knowledge sharing, and team collaboration. Beyond code, I cultivate interests in activities such as camping, music (piano), and Christian theology studies. Open to professional connections and discussions about technology, software development, and innovation - preferably accompanied by a good pizza!