### Basic CMake Project Setup Source: https://github.com/devcontainers/images/blob/main/src/cpp/test-project/CMakeLists.txt Defines the minimum CMake version, project name, and version. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.0.0) project(test-project VERSION 0.1.0) ``` -------------------------------- ### Example Jupyter Notebook URL Source: https://github.com/devcontainers/images/blob/main/src/anaconda/README.md This is an example URL format you will see in the terminal output after starting Jupyter notebooks. It includes the access token required to log in. ```bash http://127.0.0.1:8888/?token=1234567 ``` -------------------------------- ### Applying GPL to New Programs (Interactive Mode Notice) Source: https://github.com/devcontainers/images/blob/main/NOTICE.txt This is an example of a short notice to display when a program starts in interactive mode, informing users about its free software status and warranty information. ```text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Example Stub Dockerfile for Customization Source: https://github.com/devcontainers/images/blob/main/build/README.md This is an example of a user-modifiable stub Dockerfile. It allows for installing additional packages and serves as a template for customizing devcontainer images. Uncomment the RUN command to add packages. ```Dockerfile FROM mcr.microsoft.com/devcontainer/javascript-node:0-10 # ** [Optional] Uncomment this section to install additional packages. ** # # RUN apt-get update \ # && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends ``` -------------------------------- ### Start Jupyter Notebook on Container Start Source: https://github.com/devcontainers/images/blob/main/src/anaconda/README.md Configure the `postStartCommand` in `devcontainer.json` to automatically start the Jupyter notebook server when the container is created. Use `nohup` to ensure the process continues running and logs are directed to `nohup.out`. ```json // Use 'postStartCommand' to run commands after the container is created. "postStartCommand": "nohup bash -c 'jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root &'", ``` -------------------------------- ### Registering an External Dependency (kubectl) Source: https://github.com/devcontainers/images/blob/main/build/README.md Use the 'other' property to register dependencies installed directly, such as binaries. This example shows how to register kubectl, including its version command, installation path, and download URL. ```json { "other": { "kubectl": { "versionCommand": "kubectl version --client | grep -oP 'GitVersion\\s*:\\s*\\"v\\K[0-9]+\\.[0-9]+\\.[0-9]+'", "path": "/usr/local/bin", "downloadUrl": "https://github.com/kubernetes/kubectl" } } } ``` -------------------------------- ### Start Apache Web Server Source: https://github.com/devcontainers/images/blob/main/src/php/README.md Run this command in the container to start the Apache web server. Apache will be accessible on port 8080. ```bash apache2ctl start ``` -------------------------------- ### Install Node.js with Node Feature Source: https://github.com/devcontainers/images/blob/main/src/java/README.md Install any version of Node.js using the Node Feature by adding the configuration to your devcontainer.json. 'latest' will install the most recent stable version. ```json { "features": { "ghcr.io/devcontainers/features/node:1": { "version": "latest" } } } ``` -------------------------------- ### Install Maven and Gradle with Java Feature Source: https://github.com/devcontainers/images/blob/main/src/java/README.md Use the Java Feature in your devcontainer.json to install Maven and Gradle. Set 'version' to 'none' if you only need the build tools. ```json { "features": { "ghcr.io/devcontainers/features/java:1": { "version": "none", "installGradle": "true", "installMaven": "true" } } } ``` -------------------------------- ### Install packages without recommended packages Source: https://github.com/devcontainers/images/blob/main/docs/TIPS.md Use the `--no-install-recommends` flag with `apt-get` to avoid installing unnecessary recommended packages, reducing image size. ```shell apt-get -y install --no-install-recommends ``` -------------------------------- ### Example Image Tagging Source: https://github.com/devcontainers/images/blob/main/src/universal/README.md Demonstrates how to reference specific semantic versions of the universal image for consistent updates. ```text mcr.microsoft.com/devcontainers/universal:6-noble mcr.microsoft.com/devcontainers/universal:6.0-noble mcr.microsoft.com/devcontainers/universal:6.0.4-noble ``` -------------------------------- ### User Pip Install Source: https://github.com/devcontainers/images/blob/main/src/python/README.md Alternatively, stick with user-specific pip installs when using the 'vscode' non-root user. ```bash pip install --user ``` -------------------------------- ### Install Multiple Python Versions in Dockerfile Source: https://github.com/devcontainers/images/blob/main/src/python/README.md Use a Dockerfile to install multiple Python versions by specifying them in the `FROM` statement and using `apt-get` with the `deadsnakes` PPA. ```Dockerfile FROM ubuntu:jammy ARG PYTHON_PACKAGES="python3.13 python3.12 python3 python3-pip python3-venv" RUN apt-get update && apt-get install --no-install-recommends -yq software-properties-common \ && add-apt-repository ppa:deadsnakes/ppa && apt-get update \ && apt-get install -yq --no-install-recommends ${PYTHON_PACKAGES} \ && pip3 install --no-cache-dir --upgrade pip setuptools wheel ``` -------------------------------- ### Install System Packages for Vcpkg Manifest Mode Source: https://github.com/devcontainers/images/blob/main/src/cpp/README.md Installs necessary system packages for using vcpkg in manifest mode. This command is typically added to a Dockerfile. ```shell RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install autoconf automake libtool m4 autoconf-archive \ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Install Specific Python Version and Manage Pipx in Dockerfile Source: https://github.com/devcontainers/images/blob/main/src/miniconda/README.md Installs Python 3.6 and manages pipx installations within a Dockerfile. This ensures consistent setup during image builds. ```Dockerfile RUN conda install -y python=3.6 \ && pip install --no-cache-dir pipx \ && pipx uninstall pipx \ && pipx reinstall-all ``` -------------------------------- ### Applying GPL to New Programs (Source File Header) Source: https://github.com/devcontainers/images/blob/main/NOTICE.txt This is the recommended header to include at the beginning of each source file when applying the GPL. It provides a copyright line, license terms, and a disclaimer of warranty. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Example Dockerfile for Dev Image Source: https://github.com/devcontainers/images/blob/main/build/README.md This Dockerfile demonstrates how to use a 'dev' tagged image for preview or testing purposes. It contrasts with using a stable, production-ready image. ```dockerfile FROM mcr.microsoft.com/devcontainers/python:dev-3.13 # Stable/production FROM mcr.microsoft.com/devcontainers/python:3-3.13 ``` -------------------------------- ### Example Output for Dev Container Creation Source: https://github.com/devcontainers/images/blob/main/src/dotnet/README.md This output shows the successful execution of the onCreateCommand, including the generation and trust of the HTTPS development certificate within the dev container. ```text Running the onCreateCommand from devcontainer.json... The HTTPS developer certificate was generated successfully. Updating certificates in /etc/ssl/certs... rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL 1 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done. ``` -------------------------------- ### Install Specific Python Version and Manage Pipx Source: https://github.com/devcontainers/images/blob/main/src/miniconda/README.md Installs Python 3.6 and manages pipx installations. Use this in a terminal to modify an existing environment. ```bash conda install python=3.6 pip install --no-cache-dir pipx pipx uninstall pipx pipx reinstall-all ``` -------------------------------- ### Installing a Specific Python Version with Conda Source: https://github.com/devcontainers/images/blob/main/src/anaconda/README.md To install a different version of Python than the one included in the image, use the `conda install` command with the desired version specified. ```bash conda install python=3.6 ``` -------------------------------- ### Installing a Specific Python Version in a Dockerfile Source: https://github.com/devcontainers/images/blob/main/src/anaconda/README.md This snippet shows how to install a specific Python version using Conda within a Dockerfile. Ensure the `-y` flag is used for non-interactive installation. ```dockerfile RUN conda install -y python=3.6 ``` -------------------------------- ### Repository Structure Example Source: https://github.com/devcontainers/images/blob/main/build/README.md Illustrates a typical directory structure within the .devcontainer repository, showing the placement of Dockerfiles, devcontainer.json, manifest.json, and test projects. ```text 📁 .devcontainer 📄 base.Dockerfile 📄 devcontainer.json 📄 Dockerfile 📄 manifest.json 📄 README.md 📁 test-project ``` -------------------------------- ### Global Pip Install with Sudo Source: https://github.com/devcontainers/images/blob/main/src/python/README.md When using the 'vscode' non-root user, global pip installs require `sudo` by default. ```bash sudo pip install ``` -------------------------------- ### Dev Container Build Configuration Example Source: https://github.com/devcontainers/images/blob/main/build/README.md Defines build properties for a dev container image, including supported architectures, root distribution, latest tag status, and image tags. ```json { "build": { "architectures": [ "linux/amd64", "linux/arm64" ], "rootDistro": "debian", "latest": true, "tags": [ "base:${VERSION}-debian-11", "base:${VERSION}-bullseye" ] } } ``` -------------------------------- ### Configuring devcontainer.json to Use a Dockerfile Source: https://github.com/devcontainers/images/blob/main/build/README.md This devcontainer.json example shows how to configure the 'dockerFile' property to point to the Dockerfile used for building the image. A comment can be added to link to the image in this repository. ```json // For format details, see https://aka.ms/vscode-remote/devcontainer.json { "name": "Node.js 10", "dockerFile": "Dockerfile", } ``` -------------------------------- ### Installing Python Utilities with Pipx Source: https://github.com/devcontainers/images/blob/main/src/miniconda/README.md Install Python development utilities in an isolated environment using `pipx`. This prevents conflicts with the global Python environment. ```bash pipx install prospector ``` -------------------------------- ### Configure Dev Container for Persistent .NET Dev Certificates Source: https://github.com/devcontainers/images/blob/main/src/dotnet/README.md Mount a named volume to persist the x509 certificate store and use an onCreateCommand to set up the development certificate. This ensures the certificate survives container rebuilds. ```json { "mounts": [ { "type": "volume", "source": "x509stores", "target": "/home/vscode/.dotnet/corefx/cryptography/x509stores" } ], "onCreateCommand": "bash .devcontainer/setup-dotnet-dev-cert.sh" } ``` -------------------------------- ### Setup Script for .NET Dev Certificate Source: https://github.com/devcontainers/images/blob/main/src/dotnet/README.md A bash script to manage .NET development certificates within a dev container. It ensures correct ownership, generates a certificate if none exists, exports it for trusted CA usage, and updates the system's certificate store. ```bash #!/usr/bin/env bash # Change ownership of the .dotnet directory to the vscode user (to avoid permission errors) sudo chown -R vscode:vscode /home/vscode/.dotnet # If there is no development certificate, this command will generate a new one dotnet dev-certs https # Export the ASP.NET Core HTTPS development certificate to a PEM file sudo -E dotnet dev-certs https --export-path /usr/local/share/ca-certificates/dotnet-dev-cert.crt --format pem # Add the PEM file to the trust store sudo update-ca-certificates ``` -------------------------------- ### Configure Node.js Version in Dev Container Source: https://github.com/devcontainers/images/blob/main/src/ruby/README.md Specify the Node.js version to install within the Ruby dev container. Set to "none" to skip Node.js installation. ```json "args": { "VARIANT": "2", "NODE_VERSION": "14" // Set to "none" to skip Node.js installation } ```