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"]
2
Answers
ok I did this by adding
before running command
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 likeUSER XXX
with XXX being the wanted user.(link to doc : https://docs.docker.com/engine/reference/builder/#user)