How to run docker without root user in ML Batch Endpoint

Tran Hong Thu (DPS.VI.DTS) 40 Reputation points
2025-03-03T02:19:30.97+00:00

I have a project to deploy on an Azure ML batch endpoint. I need to run code in Docker without a root user (in the Batch Endpoint job). In the Dockerfile, I have to create a non-root user and grant permissions for it in the system temp folder (/tmp). However, a permission error occurs at runtime when the service creates a JSON file in a subfolder of '/tmp'. I have searched for the error and tried to fix it, but it still does not work for me. Please help me detect the root cause and suggest a solution. Below are my Dockerfile and the error message: User's image

User's image

User's image

more info, with this dockerfile i successfully ran with the ML Online Endpoint.

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,170 questions
{count} votes

Accepted answer
  1. JAYA SHANKAR G S 900 Reputation points Microsoft External Staff
    2025-03-04T06:59:46.2666667+00:00

    Hi @Tran Hong Thu (DPS.VI.DTS) ,

    when you run the job, it might take different user because the Dockerfile runs only once when you are building the environment later when you invoke it executes your scoring script with default user. You try using os.environ["AZUREML_BI_OUTPUT_PATH"] as output path instead of using /tmp or /home . you can refer this sample one where writing predictions to output path.

    Thank you


1 additional answer

Sort by: Most helpful
  1. Tran Hong Thu (DPS.VI.DTS) 40 Reputation points
    2025-03-03T07:44:07.5466667+00:00

    Hi Arko, JAYA SHANKAR G S,

    I have just tried the suggestion to change CMD ["bash", "-c", "chown -R dockeruser:dockeruser /home/dockeruser/floor && chmod -R 777 /home/dockeruser/floor && bash"], but i have still an error

    User's image

    the suggestion to change CMD ["su", "-c", "python3 main.py", "dockeruser"], i have not tried it because the Scoring script will be designated by the batch endpoint when a job starts


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.