Docker ‘Permission denied’ when not using BuildKit

  dbt, docker, docker-buildkit, permissions, python

Problem statement

I have the following Dockerfile:

ARG BASE_IMAGE=python:3.9-slim

FROM $BASE_IMAGE as base

RUN apt update && 
    apt install --yes --no-install-recommends 
        build-essential 
        libsasl2-dev && 
    apt clean

RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

RUN pip install --upgrade --no-cache-dir pip && 
    pip install --no-cache-dir dbt-spark[PyHive]==0.20.1


FROM $BASE_IMAGE as runtime

RUN apt update && 
    apt install --yes --no-install-recommends 
        ca-certificates 
        git 
        tini && 
    apt clean

ENV PATH="/opt/venv/bin:$PATH"
COPY --from=base /opt/venv /opt/venv

RUN useradd dbt --user-group --home-dir /home/dbt
USER dbt

WORKDIR /home/dbt
COPY --chown=dbt:dbt . .

ENV DBT_PROFILES_DIR=/home/dbt
RUN dbt deps

ENTRYPOINT [ "tini", "--", "dbt" ]

When I use BuildKit (DOCKER_BUILDKIT=1), the image successfully build.

When I don’t use BuildKit, I get the following error:

[Errno 13] Permission denied: 'logs'
The command '/bin/sh -c dbt deps' returned a non-zero code: 2

I try to understand why.

Additional details

I used strace to trace the system call that causes the error and here is the result:

stat("logs", 0x7ffcdbcd46b0)            = -1 ENOENT (No such file or directory)
mkdir("logs", 0777)                     = -1 EACCES (Permission denied)

Source: Docker Questions

LEAVE A COMMENT