Unable to access file structure of Docker container when running in Travis

I want to create an ArchLinux build environment in Travis, and the only good solution I’ve seen so far are Docker containers. So I created and uploaded an image using this Dockerfile:

FROM archlinux:latest

RUN pacman -Syu --noconfirm --needed base base-devel git
RUN useradd -d /home/build build
RUN mkdir -p /home/build
RUN chown -R build:build /home/build

COPY sudoers /etc/sudoers

As I can’t run makepkg as root, I create a build user. This is the .travis.yml that I then want to run:

dist: focal
os: linux

language: minimal

services:
  - docker

before_install:
  - docker pull niraami/arch-build:latest
  - docker run -itd --name build niraami/arch-build

  - docker exec build whoami
  - docker exec build pwd
  - docker exec build ls -alh
  - docker exec build sudo stat /var
  - docker exec build stat /var/lib
  - docker exec build stat /var/lib/pacman

  - docker exec build pacman -Syyu
  - docker exec build su build && cd ~
  - docker exec build git clone https://aur.archlinux.org/yay.git
  - docker exec build cd yay
  - docker exec build makepkg -si

script:
  - test

And here is the result:

docker pull niraami/arch-build:latest
before_install.2
10.61s$ docker run -itd --name build niraami/arch-build
before_install.3
0.11s$ docker exec build whoami
before_install.4
0.11s$ docker exec build pwd
0.12s$ docker exec build ls -alh
ls: cannot access 'lib64': Operation not permitted
ls: cannot access 'mnt': Operation not permitted
ls: cannot access 'root': Operation not permitted
ls: cannot access '.': Operation not permitted
ls: cannot access 'usr': Operation not permitted
ls: cannot access 'lib': Operation not permitted
ls: cannot access '..': Operation not permitted
ls: cannot access 'run': Operation not permitted
ls: cannot access 'boot': Operation not permitted
ls: cannot access 'bin': Operation not permitted
ls: cannot access 'srv': Operation not permitted
ls: cannot access 'opt': Operation not permitted
ls: cannot access 'etc': Operation not permitted
ls: cannot access 'home': Operation not permitted
ls: cannot access 'sbin': Operation not permitted
ls: cannot access 'var': Operation not permitted
ls: cannot access 'tmp': Operation not permitted
ls: cannot access 'proc': Operation not permitted
ls: cannot access '.dockerenv': Operation not permitted
ls: cannot access 'sys': Operation not permitted
ls: cannot access 'dev': Operation not permitted
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
l????????? ? ? ? ?            ? bin
d????????? ? ? ? ?            ? boot
d????????? ? ? ? ?            ? dev
-????????? ? ? ? ?            ? .dockerenv
d????????? ? ? ? ?            ? etc
d????????? ? ? ? ?            ? home
l????????? ? ? ? ?            ? lib
l????????? ? ? ? ?            ? lib64
d????????? ? ? ? ?            ? mnt
d????????? ? ? ? ?            ? opt
d????????? ? ? ? ?            ? proc
d????????? ? ? ? ?            ? root
d????????? ? ? ? ?            ? run
l????????? ? ? ? ?            ? sbin
d????????? ? ? ? ?            ? srv
d????????? ? ? ? ?            ? sys
d????????? ? ? ? ?            ? tmp
d????????? ? ? ? ?            ? usr
d????????? ? ? ? ?            ? var
The command "docker exec build ls -alh" failed and exited with 1 during .
Your build has been stopped.

Originally, I did not have the whoami, pwd and other seemingly random commands there, but I was getting strange errors… Turns out I cannot access any files inside of the docker container as you can see by the build log (output of ls -alh).

I’ve tried this exact same build process on my ArchLinux, as well as a Ubuntu Desktop (focal) VM, and there are no issues… So the docker image cannot be the problem. I’m planning to switch over to GitHub actions anyways, but I wanted to know why this happens because I find it very intriguing.

Imprint