Using VSCode DevContainer for rust development

In order to develop rust inside a devcontainer , on windows with docker vm, or linux with docker, you need the below files:

File Structure

🔗devcontainer.json

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/python-3-postgres
// Update the VARIANT arg in docker-compose.yml to pick a Python version
{
  "name": "Yew Rust",
  "dockerComposeFile": "../docker/docker-compose.devel.yml",
  "service": "myapp",
  "workspaceFolder": "/workspace",
  // Set *default* container specific settings.json values on container create.
  // "settings": {
  // 	"python.defaultInterpreterPath": "/usr/local/bin/python",
  // 	"python.linting.enabled": true,
  // 	"python.linting.pylintEnabled": true,
  // 	"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
  // 	"python.formatting.blackPath": "/usr/loal/py-utils/bin/black",
  // 	"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
  // 	"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
  // 	"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
  // 	"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
  // 	"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
  // 	"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
  // 	"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
  // 	"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
  // },
  // Add the IDs of extensions you want installed when the container is created.
  "extensions": [
   ]
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  // "forwardPorts": [
  // 	3306
  // ],
  // Use 'postCreateCommand' to run commands after the container is created.
  // "postCreateCommand": "pip install --user -r requirements.txt",
  // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
  //"remoteUser": "vscode"
}

🔗docker-compose.devel.yml

version: '3.8'

services:
  myapp:
    build:
      context: ..
      dockerfile: docker/Dockerfile_devel
      args:
        # Update 'VARIANT' to pick a version of Python: 3, 3.10, 3.9, 3.8, 3.7, 3.6
        # Append -bullseye or -buster to pin to an OS version.
        # Use -bullseye variants on local arm64/Apple Silicon.
        VARIANT: 3-bullseye
        # Optional Node.js version to install
        NODE_VERSION: "lts/*"
    restart: unless-stopped
    volumes:
    - ..:/workspace:cached
    environment:
      #https://stackoverflow.com/questions/64297778/hot-reload-hmr-webpack-not-working-on-docker-container-wsl2
      CHOKIDAR_USEPOLLING: true
    # Overrides default command so things don't shut down after the process ends.
    command: sleep infinity
    

    # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
    #network_mode: service:db
        # Uncomment the next line to use a non-root user for all processes.
        # user: vscode

        # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
        # (Adding the "ports" property to this file will not forward from a Codespace.)

🔗Dockerfile-devel


# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
#ARG PYTHON_VERSION=3.9-slim-bullseye
FROM debian:bullseye-slim


#ENV PYTHONDONTWRITEBYTECODE 1
#ENV PYTHONUNBUFFERED 1
#ENV BUILD_ENV ${BUILD_ENVIRONMENT}


RUN apt-get update && apt-get install --no-install-recommends -y \
  build-essential curl wget ca-certificates






RUN apt-get update

# Get Rust
RUN echo "fs.inotify.max_user_watches=524288" > /etc/sysctl.conf
RUN curl https://sh.rustup.rs -sSf | \
  sh -s -- --default-toolchain stable -y
ENV PATH=/root/.cargo/bin:$PATH

RUN rustup component add rustfmt
RUN cargo install systemfd
RUN cargo install cargo-watch
RUN cargo install trunk
RUN rustup target add wasm32-unknown-unknown

WORKDIR /
COPY ./entrypoint.sh /entrypoint.sh

#ENTRYPOINT ["/entrypoint.sh"]