I have this Dockerfile:
FROM ubuntu:bionic
RUN mkdir /usr/custom
ADD script.sh /usr/custom
RUN chmod =rx /usr/custom/script.sh
RUN useradd -ms /bin/bash -u 1001 someusr
USER someusr
WORKDIR /home/someusr
where script.sh (it is in the same directory as Dockerfile) contains:
#!/bin/bash
whoami
Build the image with:
docker image build --tag my_ubuntu_bionic:auto .
Then run it with:
docker run --rm --name ubl --user=1001 my_ubuntu_bionic:auto /usr/custom/script.sh
and it displays root.
How can I run the script as someusr
? The --user
parameter doesn't seem to have any effect (--user=someusr
doesn't work).
Ultimately I want script.sh to execute in the context of a user that has minimum permissions. The solutions that I've seen on SO assume a linux host.
Versions:
Docker version 19.03.5, build 2ee0c57608
OS Name: Microsoft Windows Server 2019 Datacenter
Version: 10.0.17763 Build 17763
Thanks