Search code examples
bashdockerpermissions

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


Solution

  • 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'