opcode icon indicating copy to clipboard operation
opcode copied to clipboard

issue passing in docker compose options

Open robwilde opened this issue 4 years ago • 3 comments

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.

robwilde avatar Apr 25 '22 04:04 robwilde

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:

  1. a minimal Dockerfile
  2. a minimal docker-compose.yml
  3. 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.

DannyBen avatar Apr 25 '22 06:04 DannyBen

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

DannyBen avatar Apr 25 '22 07:04 DannyBen

I am assuming this is resolved, feel free to comment if not.

DannyBen avatar May 04 '22 19:05 DannyBen