Home > Blockchain >  Run Dockerfile Python script as non-root user
Run Dockerfile Python script as non-root user

Time:07-26

I have Dockerfiles with some script, what should I do to run the script as non-root user?

FROM python:3.9
WORKDIR /
COPY . /
RUN pip install --no-cache-dir --upgrade -r /requirements.txt
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "80"]

CodePudding user response:

You have to use the USER keyword to switch from the default root user.

Before the line with the RUN, you can put a line like USER XXX with XXX being the wanted user.

(link to doc : https://docs.docker.com/engine/reference/builder/#user)

CodePudding user response:

ok I did this by adding

RUN groupadd -r user && useradd -r -g user user
USER user

before running command

  • Related