Create a custom Docker dev environment

  docker, dockerfile, visual-studio-code

I like the Docker dev environment tool but I’d like to also be able have some tools preinstalled when a user clones the repository using the Docker Dev Environment tool.

I’ve have a .devcontainer folder in the repository with a Dockerfile:

# [Choice] Alpine version: 3.13, 3.12, 3.11, 3.10

# Install Terraform CLI

# Install GCloud SDK

And a devcontainer.json file:

    "name": "Alpine",
    "build": {
        "dockerfile": "Dockerfile",
        // Update 'VARIANT' to pick an Alpine version: 3.10, 3.11, 3.12, 3.13
        "args": { "VARIANT": "3.13" }
    // Set *default* container specific settings.json values on container create. 
    "settings": {},

    // Add the IDs of extensions you want installed when the container is created.
    // Note that some extensions may not work in Alpine Linux. See
    "extensions": [],

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "uname -a",

    // Uncomment when using a ptrace-based debugger like C++, Go, and Rust
    // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

    // Comment out connect as root instead. More info:
    "remoteUser": "vscode"

I’ve tried to include curl and install commands in the Dockerfile but the commands just don’t seem to work. To clarify, once the container is built I can’t seem to access the CLI tools eg. terraform --version says terraform not found.

The docker launches as a VSCode window running in the container and I am attempting to use the CLI tools from the VSCode terminal if that makes a difference.

Source: Docker Questions