VSCode
Various tips and gotchas.
This is the Dockerfile for the devcontainer I sometimes use. Like most of what you read on this site it’s a bit opinionated in how it’s structured and which tools are added, modify it to fit your needs.
This container supports Linux and Android development.
If you are going to use it on Windows, make sure to read the WSL2 instructions on setting that up before you start using this.
{ "name": "Dev Container", "runArgs": [ // "--privileged" // Required if you need to run Electron apps // "--network=host", // May fix networking for you "--device=/dev/kvm" // Enables virtualization inside the container ], "build": { "dockerfile": "Dockerfile", "args": { // All Dockerfile ARGs can be overridden here } }, "customizations": { "settings": { "extensions.installRecommended": true }, "extensions": [ "rust-lang.rust-analyzer", // Recommended, rust-analyzer, to validate Rust code "tauri-apps.tauri-vscode", // Recommended, tauri.conf.json schema ] }, "remoteUser": "vscode", // The name of the non-root user in the container "features": {}}
# syntax=docker/dockerfile:1.4# Arguments for setting up the SDK. Can be overridden in devcontainer.json but shouldn't be requiredARG ANDROID_SDK_TOOLS_VERSION="9477386"ARG ANDROID_PLATFORM_VERSION="32"ARG ANDROID_BUILD_TOOLS_VERSION="30.0.3"ARG NDK_VERSION="25.0.8775105"
# Arguments for the Node.js version to install along with npm, yarn and pnpmARG NODE_VERSION="18"
# Argument for the mold linker version to installARG MOLD_VERSION="v1.11.0"
# Argument for the pnpm version to installARG PNPM_VERSION="8.5.1"
# Argument for the branch to use for the Tauri CLIARG TAURI_CLI_VERSION="2.0.0-alpha.9"
# Argument for the Java version to useARG JAVA_VERSION="17"
# Arguments related to setting up a non-root user for the containerARG USERNAME=vscodeARG USER_UID=1000ARG USER_GID=$USER_UID
# Arguments for installing dependencies where DEPENDENCIES are Tauri dependencies and EXTRA_DEPENDENCIES is empty so that users can add more without interfering with TauriARG TAURI_DEPENDENCIES="build-essential curl libappindicator3-dev libgtk-3-dev librsvg2-dev libssl-dev libwebkit2gtk-4.1-dev wget libappimage-dev"ARG EXTRA_DEPENDENCIES=""
# Argument for which image version to useARG IMAGE="mcr.microsoft.com/vscode/devcontainers/base"ARG VARIANT="0-ubuntu-22.04"
######################################## Base image## Installing dependencies######################################FROM ${IMAGE}:${VARIANT} AS base_image
# Redefine argumentsARG TAURI_DEPENDENCIESARG EXTRA_DEPENDENCIES
# Non-interactive frontendENV DEBIAN_FRONTEND=noninteractive
# Install dependenciesRUN <<EOT apt update # Install general dependencies apt install -yq --no-install-recommends sudo openjdk-17-jdk openjdk-17-jre \ wget curl xz-utils zip unzip file socat clang libssl-dev \ pkg-config git git-lfs bash-completion llvm \ # Install Tauri dependencies as well as extra dependencies apt install -yq --no-install-recommends ${TAURI_DEPENDENCIES} ${EXTRA_DEPENDENCIES}EOT
######################################## Android SDK## Downloading and installing######################################FROM base_image as android_sdkWORKDIR /android_sdk
# Redefine argumentsARG ANDROID_SDK_TOOLS_VERSIONARG ANDROID_PLATFORM_VERSIONARG ANDROID_BUILD_TOOLS_VERSIONARG NDK_VERSIONARG JAVA_VERSION
# Environment variables inside the android_sdk step to ensure the SDK is built properlyENV ANDROID_HOME="/android_sdk"ENV ANDROID_SDK_ROOT="$ANDROID_HOME"ENV NDK_HOME="${ANDROID_HOME}/ndk/${NDK_VERSION}"ENV PATH=${PATH}:/android_sdk/cmdline-tools/latest/binENV JAVA_HOME=/usr/lib/jvm/java-${JAVA_VERSION}-openjdk-amd64
# Set up the SDKRUN curl -C - --output android-sdk-tools.zip "https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip" \ && mkdir -p /android_sdk/cmdline-tools/latest/ \ && unzip -q android-sdk-tools.zip -d /android_sdk/cmdline-tools/latest/ \ && mv /android_sdk/cmdline-tools/latest/cmdline-tools/* /android_sdk/cmdline-tools/latest \ && rm -r /android_sdk/cmdline-tools/latest/cmdline-tools \ && rm android-sdk-tools.zip \ && yes | sdkmanager --licenses \ && touch $HOME/.android/repositories.cfg \ && sdkmanager "cmdline-tools;latest" \ && sdkmanager "platform-tools" \ && sdkmanager "emulator" \ && sdkmanager "ndk;${NDK_VERSION}" \ && sdkmanager "platforms;android-${ANDROID_PLATFORM_VERSION}" \ && sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" \ && sdkmanager "system-images;android-${ANDROID_PLATFORM_VERSION};google_apis;x86_64"
# As an added bonus we set up a gradle.properties file that enhances Gradle performanceRUN echo "org.gradle.daemon=true" >> "/gradle.properties" \ && echo "org.gradle.parallel=true" >> "/gradle.properties"
######################################## Mold## Speeds up compilation######################################FROM base_image as moldWORKDIR /mold
# Redefine argumentsARG MOLD_VERSION
# Install dependenciesRUN apt update && apt install -yq zlib1g-dev cmake zlib1g-dev gcc g++
# Clone mold, build it then install itRUN git clone https://github.com/rui314/mold.git \ && mkdir mold/build \ && cd mold/build \ && git checkout --quiet ${MOLD_VERSION} \ && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ .. \ && cmake --build . -j $(nproc) \ && cmake --install .
# Set up a config.toml file that makes Cargo use clang and moldRUN echo "[profile.debug.target.x86_64-unknown-linux-gnu]" >> /config.toml \ && echo "linker = \"clang\"" >> /config.toml \ && echo "rustflags = [\"-C\", \"link-arg=-fuse-ld=/usr/local/bin/mold\"]" >> /config.toml \ && echo "[registries.crates-io]" >> /config.toml \ && echo "protocol = \"sparse\"" >> /config.toml \ && echo "[net]" >> /config.toml \ && echo "git-fetch-with-cli = true" >> /config.toml
######################################## The finalized container## Puts it all together######################################FROM base_image
# Redefine argsARG ANDROID_SDK_TOOLS_VERSIONARG ANDROID_PLATFORM_VERSIONARG ANDROID_BUILD_TOOLS_VERSIONARG NDK_VERSIONARG USERNAMEARG USER_UIDARG USER_GIDARG NODE_VERSIONARG TAURI_CLI_VERSIONARG JAVA_VERSION
# Set up the required Android environment variablesENV ANDROID_HOME="/home/${USERNAME}/android_sdk"ENV ANDROID_SDK_ROOT="$ANDROID_HOME"ENV NDK_HOME="${ANDROID_HOME}/ndk/${NDK_VERSION}"ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/emulatorENV JAVA_HOME=/usr/lib/jvm/java-${JAVA_VERSION}-openjdk-amd64
# Ensure the user is a sudo user in case the developer needs to e.g. run apt install laterRUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME
# Install Node.jsRUN curl -sL "https://deb.nodesource.com/setup_${NODE_VERSION}.x" | bash -E - \ && apt update \ && apt install -yq nodejs \ && npm i -g npm \ && npm i -g yarn \ && npm i -g pnpm@${PNPM_VERSION}
# Set up pnpmRUN SHELL=bash pnpm setup
# Clean up to reduce container sizeRUN apt clean \ && rm -rf /var/lib/apt/lists/*
# Run the rest of the commands as the non-root userUSER $USERNAME
# Install rustupRUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y
# Ensure the Cargo env gets loadedRUN echo "source /home/${USERNAME}/.cargo/env" >>/home/${USERNAME}/.bashrc
# Add Cargo bin to the PATH, primarily to ensure the next command can find rustupENV PATH="/home/${USERNAME}/.cargo/bin:$PATH"
# Update Rust and install required Android targetsRUN rustup update \ # Android targets && rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android \ # Add WASM support && rustup target add wasm32-unknown-unknown \ # Install Trunk && cargo install trunk --git https://github.com/amrbashir/trunk \ # Install Tauri CLI && cargo install tauri-cli@${TAURI_CLI_VERSION}
# Copy files from moldCOPY --from=mold --chown=${USERNAME}:${USERNAME} /usr/local/bin/mold /usr/local/bin/moldCOPY --from=mold --chown=${USERNAME}:${USERNAME} /config.toml /home/${USERNAME}/.cargo/config.toml
# Copy files from android_sdkCOPY --from=android_sdk --chown=${USERNAME}:${USERNAME} /gradle.properties /home/${USERNAME}/.gradle/gradle.propertiesCOPY --from=android_sdk --chown=${USERNAME}:${USERNAME} /android_sdk /home/${USERNAME}/android_sdk
# Create an emulatorRUN echo no | avdmanager create avd -n dev -k "system-images;android-${ANDROID_PLATFORM_VERSION};google_apis;x86_64"
# Add ~/.bin to the PATHRUN mkdir -p /home/${USERNAME}/.bin \ && echo "export PATH=/home/${USERNAME}/.bin:$PATH" >>/home/${USERNAME}/.bashrc