Seura
Seura

Reputation: 55

permission denied while execute command on docker container

I'm trying to execute command on a docker container from the docker host but got permission denied. I want to send notification to docker log once new version uploaded. Tried to use --user appuser, without success.

my command: docker exec --workdir /app my-container printf 'NEW VERSION UPLOADED %s\n' "$(printenv VERSION)" >> /proc/1/fd/1

the error i got: -bash: /proc/1/fd/1: Permission denied

How can i do that?

Thank you

Upvotes: 0

Views: 3096

Answers (1)

Dr Claw
Dr Claw

Reputation: 686

Actually docker exec --workdir /app my-container printf 'NEW VERSION UPLOADED %s\n' "$(printenv VERSION)" >> /proc/1/fd/1 will try to write to /proc/1/fd/1 of your host and not to the container.

Also appuser don't have the permission to write to proc/fd, so --user root must be used if there is USER appuser in the Dockerfile (which means that the default user is appuser).

So your command should be:

docker exec --workdir /app my-container --user root \
 /bin/sh -c 'printf "NEW VERSION UPLOADED %s\n"  "$(printenv VERSION)" >> /proc/1/fd/1'

Upvotes: 1

Related Questions