VS Code + Clang-Tidy + Docker
- https://apt.llvm.org/
- https://clang.llvm.org/extra/clang-tidy/
- .vscode/settings.json (UI: [add item] without any quotation marks, like
-clang-tidy){ "clangd.arguments": [ "-clang-tidy", "--compile-commands-dir=${workspaceFolder}/build" ], }
❯ docker build -t cxx-env .
❯ sudo docker commit 8e2cb27df6a0 arbitrary-new-name
sha256:06900f3042303073b0fa41c290eb5979b360cb3635205a1d9d0653881ca2b552
❯ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
arbitrary-new-name latest 06900f304230 4 seconds ago 10.1kB
cxx-env latest 595f2b5bafd9 4 hours ago 2.12GB
hello-world latest 74cc54e27dc4 2 weeks ago 10.1kB
❯ xhost
access control enabled, only authorized clients can connect
❯ xhost +
access control disabled, clients can connect from any host
❯ sudo docker run -it -v ./workspace:/workspace -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY --device /dev/dri --rm --name misra-1 vscode:v0.2
root@ecbd2ab04094:/workspace# code --no-sandbox --user-data-dir=/workspace/vscode-usrdata
# Use Ubuntu 24.04 as the base image
FROM ubuntu:24.04
# Suppress interactive installation prompts
ENV DEBIAN_FRONTEND=noninteractive
# Update package list and install required packages
RUN apt-get update && apt-get install -y \
wget \
software-properties-common \
apt-transport-https \
gnupg2
# Install NeoVim
RUN apt-get install -y neovim
# Install clang 14, clangd 14, and clang-tidy 14
RUN apt-get install -y clang-14 clangd-14 clang-tidy-14
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 100
RUN update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-14 100
RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-14 100
# Add Microsoft GPG keys and repository for VS Code
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /usr/share/keyrings/ms.gpg \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/ms.gpg] https://packages.microsoft.com/repos/code stable main" \
> /etc/apt/sources.list.d/vscode.list
# Install VS Code
RUN apt-get update && apt-get install -y code
RUN add-apt-repository -y ppa:mozillateam/ppa
RUN apt update && apt install -y fireforx
# Create a workspace directory and set it as the default
RUN mkdir -p /workspace
WORKDIR /workspace
# Declare a volume to allow host code sharing
VOLUME ["/workspace"]