I am using CLion and I want to build keepassxc with CMAKE in Docker Desktop. Using the Docker to build this project leads to a permission denied error.
I am using Ubuntu 22.04 with CLion 2024.2.2 and Docker Desktop 4.34.2
I followed the steps mentioned in the tutorial to create a Docker toolchain in CLion.
The first problem was that CLion could not find the paths to the compilers in the docker container and the error log shows the following
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - broken
-- Configuring incomplete, errors occurred!
Error code: 1
So I set paths to the compiler and build tool manually.
But running the build process leads to a CMake error.
This is a snippet from the error. In the error message were also other directories and files mentioned, where the permission is denied.
CMake Error at /usr/share/cmake-3.22/Modules/CMakeDetermineSystem.cmake:181 (file):
file failed to open for writing (Permission denied):
/tmp/keepassxc/cmake-build-debug-docker/CMakeFiles/CMakeOutput.log
Call Stack (most recent call first):
CMakeLists.txt:19 (project)
So I set the permission for the directory cmake-build-debug-docker
to 0777 and building with Docker completed without any errors. But the problem is that the files like the executable, that are created in the Docker Container, are owned by the user id 100999, which is not my user id.
In the above mentioned tutorial it is stated that CLion will run the Docker container with the user id of the host user, when the Docker installation is not rootless. But I am running Docker Desktop with user permissions. Also Docker Desktop use user namespace remapping. I think this is the cause for this owner id mismatch.
I tried a fix for this problem, which is mentioned in the tutorial and added following lines in the Dockerfile:
ARG UID=1000
RUN useradd -m -u ${UID} -s /bin/bash builder
USER builder
But this not change the outcome.
I don't know how to fix this problem.
The Dockerfile I use for building:
FROM ubuntu:jammy
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y \
asciidoctor \
build-essential \
clang \
cmake \
gcc \
gdb \
g++ \
make
RUN apt install -y \
qtbase5-dev qtbase5-private-dev qttools5-dev qttools5-dev-tools \
libqt5svg5-dev libargon2-dev libminizip-dev libbotan-2-dev libqrencode-dev \
libkeyutils-dev zlib1g-dev libreadline-dev libpcsclite-dev libusb-1.0-0-dev \
libxi-dev libxtst-dev libqt5x11extras5-dev
I finally found a solution for this problem.
In CLion under Settings > Build, Execution, Deployment > Toolchains add to the Container settings the Option --user=0
.
With this option the command will be run as the root user in the container. Because Docker Desktop runs as the normal user the root user in the Container will be mapped to the host user.
After adding this setting CLion found automatically the paths to the compiler in the Docker container and building works without any permission issues. Also the files in the build directory are owned by my host user.