issue passing in docker compose options
currently have the following command for running in containers
dbashr: docker compose exec web_local bash -c
the default user in container is root attempting to run commands in containers as the www-data user
dbash: docker compose exec --user www-data web_local bash -c
but this still runs as root. it appears the --user www-data is ignored or not added
also tried:
dbash: docker compose exec -u www-data dms_web_local bash -c
dbash: docker compose exec --user=www-data dms_web_local bash -c
all 3 of these commands do work in the same terminal on there own. Any ideas on how to make this work. Thanks for any and all assistance.
Well, there is no reason for opcode to ignore any argument.
I suspect that it is something to with your bash -c at the end.
Can you try adding "$@" at the end of the opcode command?
dbash: docker compose exec --user www-data web_local bash -c "$@"
If this doesn't work, I would need a way to reproduce the problem, so I will need:
- a minimal Dockerfile
- a minimal docker-compose.yml
- a sample failing command
On a side note, there might be easier ways to run commands on the container - check why you need the bash -c in the first place.
Does this seem like a reasonable representation of the problem (and solution)?
Dockerfile
FROM alpine
RUN adduser -S theboss
RUN apk add --no-cache bash
USER theboss
docker-compose.yml
services:
test:
build: .
image: temp
op.conf
test: docker-compose exec --user theboss test bash -c "$@"
Run
$ docker run --rm -it test
# in another terminal
$ op test "whoami ; whoami"
Output
theboss
theboss
I am assuming this is resolved, feel free to comment if not.