0

Currently, I drop into docker bash using the command docker exec -it jboss /bin/bash and then navigate to the log directory cd /blah/blah/blah/logs/ so I can tail different logs that are dumped there.

If I set up an alias to do one command after the other using && or ; then it doesn't work because (I assume) that bash is running the second cd command inside the original shell rather than the new docker bash I just dropped into.

I am also aware that docker has a built in log command to do this, but there are multiple different log files that I want to tail.

I tried to utilize the --rcfile trick like docker exec -it jboss /bin/bash --rcfile <(echo 'ls') but wasn't able to figure it out: How to invoke bash, run commands inside the new shell, and then give control back to user?

Has anyone accomplished something like this in the past? Thanks in advance.

cjnash
  • 1,228
  • 3
  • 19
  • 37
  • Please read `docker exec --help` – KamilCuk Jan 14 '21 at 15:30
  • @KamilCuk okay, not much info there... -d, -e and -u don't really help here from what I am seeing, and I am currently trying to drop into interactive with -i. Are you suggesting using the [ARG...] ? I've tested trying to navigate to the directory using -c and passing in a cd but it exits out of interactive... guess I'll keep on chugging along – cjnash Jan 14 '21 at 15:54
  • And the `-w` option? – KamilCuk Jan 14 '21 at 15:55
  • 1
    Not seeing that option. FML must be behind in docker versions.... Currently on 13.1... really need to upgrade. Thanks – cjnash Jan 14 '21 at 15:57

1 Answers1

1

If you want to start from some directory when inside a container, use -w or --workdir option:

docker exec -it -w /blah/blah/blah/logs/ jboss bash

If that option is missing and you want to execute a command before navigating to shell, the simplest there is:

# Don't in case of strange path!
docker exec -it jboss bash -c "cd /blah/blah/blah/logs/ && bash"
# Better pass properly quoted argument in case of strange paths:
docker exec -it jboss bash -c 'cd "$1" && bash' -- "/blah/blah/blah/logs/"
docker exec -it jboss bash -c 'cd '"$(printf "%q" "/blah/blah/blah/logs/")"' && bash'
KamilCuk
  • 120,984
  • 8
  • 59
  • 111