Dockerfile permission denied error (Streamlit / OpenShift)

I used this template Dockerfile from Deploy Streamlit using Kubernetes - Streamlit Docs to create a container. The build runs through and is passed, but the container/pod shows an error concerning run.sh:

Error: container create failed: time=“2023-11-07T23:40:52Z” level=error msg=“runc create failed: unable to start container process: exec: “./run.sh”: permission denied”

Whats the problem here?

Please respect to the very small changes in the Dockerfile, because I cannot use git clone there. But this is not the question - the question it why this “template” offered from streamlit does not work.

FROM python:3.8-slim

RUN groupadd --gid 1000 appuser \
    && useradd --uid 1000 --gid 1000 -ms /bin/bash appuser

RUN pip3 install --no-cache-dir --upgrade \
    pip \
    virtualenv

RUN apt-get update && apt-get install -y \
    build-essential \
    software-properties-common \
    git

USER appuser
WORKDIR /home/appuser

# DELETED, BECAUSE NO REPO-ACCESS
RUN git clone https://github.com/streamlit/streamlit-example.git app

#THEREFORE ADDED (hope this is similar to the repo clone with ./app/?)
COPY main.py ./app/
COPY requirements.txt ./app/

ENV VIRTUAL_ENV=/home/appuser/venv
RUN virtualenv ${VIRTUAL_ENV}
RUN . ${VIRTUAL_ENV}/bin/activate && pip install -r app/requirements.txt

EXPOSE 8501

COPY run.sh /home/appuser
ENTRYPOINT ["./run.sh"]

The file run.sh also from streamlit docs is untouched (changed only the name of file to main.py)

#!/bin/bash

APP_PID=
stopRunningProcess() {
    # Based on https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script
    if test ! "${APP_PID}" = '' && ps -p ${APP_PID} > /dev/null ; then
       > /proc/1/fd/1 echo "Stopping ${COMMAND_PATH} which is running with process ID ${APP_PID}"

       kill -TERM ${APP_PID}
       > /proc/1/fd/1 echo "Waiting for ${COMMAND_PATH} to process SIGTERM signal"

        wait ${APP_PID}
        > /proc/1/fd/1 echo "All processes have stopped running"
    else
        > /proc/1/fd/1 echo "${COMMAND_PATH} was not started when the signal was sent or it has already been stopped"
    fi
}

trap stopRunningProcess EXIT TERM

source ${VIRTUAL_ENV}/bin/activate

streamlit run ${HOME}/app/main.py &
APP_ID=${!}

wait ${APP_ID}#!/bin/bash

hi @teq508
The “permission denied” error you are encountering is likely due to the fact that the run.sh script does not have the necessary execute permissions. You can fix this by adding the execute permission to the script before running it.

Modify your Dockerfile to include the following lines after copying the run.sh script:

COPY run.sh /home/appuser
RUN chmod +x /home/appuser/run.sh

After making this change, rebuild your Docker image and try running it again. This should resolve the “permission denied” issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.