How to use su command in Alpine

3 posts / 0 new
Last post
#1 Mon, 2017-10-30 19:02
Jun
  • Jun's picture
  • Offline
  • Last seen: 5 months 2 days ago
  • Joined: 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!

Mon, 2017-10-30 21:27
Head_on_a_Stick
  • Head_on_a_Stick's picture
  • Offline
  • Last seen: 1 week 1 day ago
  • Joined: 2016-05-01

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?

Tue, 2017-10-31 00:46
Jun
  • Jun's picture
  • Offline
  • Last seen: 5 months 2 days ago
  • Joined: 2017-10-30

Thanks for the reply. I actually got su command work as below
CMD [ "su", "-s", "/bin/bash", "-c", "my_bash_script", "my_user" ]

Log in or register to post comments