When I use docker, I want to do some operations in the container for host by docker exec
, I meet the problem.
I want do something like this but with error:
# in host
docker exec test-container bash -c "for i in `ls /folder-in-docker`; do someoperationon($i); done"
I simplify the problem reproduced with a command:
# host environment
docker exec test-container bash -c "for i in `ls /`; do echo $i; done"
>! bash: -c: line 2: syntax error near unexpected token `boot'
>! bash: -c: line 2: `boot
I want the code "for i in ls /
; do echo $i; done" executed in the container, but ls /
is done in the host environment.
In host environment, the result ls /
is
bin boot cdrom dev etc home lib lib32 lib64 libx32 lost+found media mnt opt proc root run sbin snap srv sys tmp usr var
I try other way like $(ls /)
, but also with error:
docker exec test bash -c "for i in $(ls /); do echo $i; done"
>! bash: -c: line 2: syntax error near unexpected token `boot'
>! bash: -c: line 2: `boot'