How to use su command in Alpine
#1
Mon, 2017-10-30 19:02
Jun
-
- Offline
- 5 months 2 days ago
- 2017-10-30
I was trying to build a Java application docker image based on Alpine-Java. I added a group and user, then try to run a bash shell script on that newly created user. I was not able to make the su command work. Here is my Docker file.
FROM anapsix/alpine-java:jdk7 # Create group and User ... CMD ["su", “my_user”, "-c", “my_bash_script“]
When run the docker container, I got the following error.
halt: unrecognized option: c BusyBox v1.24.2 (2016-06-23 08:49:16 GMT) multi-call binary. Usage: halt [-d DELAY] [-n] [-f] Halt the system -d SEC Delay interval -n Do not sync -f Force (don't go through init)
If I changed the CMD to the following, got same error
CMD ["su", "-c", “my_bash_script“, “-“, “my_user”]
Can anyone help? Thanks!
Have you tried using /bin/su instead of plain su?
Can you check the output of this command in your container:
which -a su
How are you setting $PATH?
Thanks for the reply. I actually got su command work as below
CMD [ "su", "-s", "/bin/bash", "-c", "my_bash_script", "my_user" ]