1

Given this bug.cpp file:

#include <thread>
int main() {
  auto t = std::thread([] {});
  t.join();
  return 0;
}

And this docker container:

FROM ubuntu:22.04
RUN sed -i -e 's/^APT/# APT/' -e 's/^DPkg/# DPkg/' /etc/apt/apt.conf.d/docker-clean
RUN apt-get update -y
RUN apt-get install -y g++

compiling the example with:

#!/usr/bin/env sh
docker build -t test:0 -f Dockerfile .
docker run -u $(id -u):$(id -g) -v $(pwd):/src -w /src test:0 bash -c "g++ -pthread -o bug bug.cpp && ./bug"

fails with:

terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted

Replacing ubuntu:22.04 with ubuntu:20.04 and ubuntu:21.10 does work, so my hypothesis is that something has changed in how Ubuntu 22.04 handles pthreads.

What changed from Ubuntu 21.10 to 22.04 that breaks this and how do I fix it?


PS: the sed above is required because something else broke in Ubuntu 22.04 as well that prevents installing any packages in docker containers...

gnzlbg
  • 111

2 Answers2

1

The issue with threading has to do with the version of Docker being used. Newer GLIBC that is in 22.04 uses the CLONE3 syscall, which is not in the Default SECCOMP profile in earlier versions of Docker. See related posting at https://github.com/adoptium/containers/issues/215#issuecomment-1142046045.

So you need to upgrade to later Docker, or adjust your SECCOMP profile for the Container. Information contained at the posting above.

jhawkins
  • 11
  • 1
0

Ubuntu 20.04 shipped with g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 as default, I solved similar issue with thread module by installing g++ 11

Current version:

g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Add Repository:

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test

install g++ version 11

sudo apt install -y g++-11

Now you can verify that the installation finished successfully by checking g++ version:

g++ --version
g++ (Ubuntu 11.2.0-1ubuntu1~20.04.1) 11.4.2
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If above does not fix your issue you can completely remove g++ 11 and related dependencies, run the following command:

sudo apt purge --autoremove -y gcc-11

Remove GPG key and repository:

sudo rm -rf /etc/apt/trusted.gpg.d/ubuntu-toolchain-r_ubuntu_test.gpg
sudo rm -rf /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-focal.list
dileepa
  • 85