I am trying to run specific command inside running docker container.
Docker exec -t t1 ls /tmp/sth/*
in return I receive
ls: cannot access '/tmp/sth/*': No such file or directory
In fact when I execute command while inside container everything works. Container is using Debian and local machine is using Windows. I was trying to find it, but could not.
The exec command is used to interact with already running containers on the Docker host. It allows you to start a session within the default directory of the container. Sessions created with the exec command are not restarted when the container is restarted.
In order to execute multiple commands using the “docker exec” command, execute “docker exec” with the “bash” process and use the “-c” option to read the command as a string. Note: Simple quotes may not work in your host terminal, you will have to use double quotes to execute multiple commands.
Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the --workdir flag to specify the directory: docker exec --workdir /tmp container-name pwd.
If you want a shell inside the container to expand your glob, you need to... well... actually run a shell inside the container. The one outside the container can't see files inside the container (of course), so it passes ls
the literal pattern, not a list of files in the directory as you intend.
Thus:
docker exec -t t1 sh -c "ls /tmp/sth/*"
...note that I'd usually use single-quotes for the command, but since your host is Windows, using double quotes since they're more likely to work from cmd.exe
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With