2

I have a docker image that runs on linux alpine. Sudo is not installed. I would like to build the image with a non-root user but I need to run a start script from CMD as root after the image is build.

I need to open the container in vscode and if the USER is root then all new files created inside the container environment (and mounted in a volume) will be owned by root and therefore needs sudo to modify from the host system.

If I change the USER to anything but root in the Dockerfile, then the start.sh script running in my parent image CMD cannot run.

I have tried a few things like:

  1. Dockerfile RUN is done as root and the start.sh script ends with: su . to change the user back to the non root. This has no effect on vscode ownership. I can then create new files from the terminal with the non root user, but I would rather be able to use vscode create new file (which is still owned by root)
  2. Override the CMD to run with sudo (but sudo not installed. And I do not want to install it)
  3. CMD su root -c /start.sh but I dont know the root password in the docker image, and I do not want to modify the root password

Any help with finding a way to run my start.sh script with root privileges without using sudo would be greatly appreciated.

user2911833
  • 21
  • 1
  • 3
  • Are you saying you need the `CMD` to run as root but that it should create files on a mounted volume as another user? – l0b0 Jul 04 '20 at 23:24
  • Just change mod in the host mount dir. `chmod +x dirname` you can also do it inside the container. – Shmuel Sep 07 '20 at 15:27

0 Answers0