Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using '*' in docker exec command

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.

like image 857
Wiciaq123 Avatar asked Jun 07 '18 13:06

Wiciaq123


People also ask

What you can do with the Docker EXEC command?

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.

How do I run multiple commands in Docker exec?

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.

Which command can exec commands inside docker container?

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.


1 Answers

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.

like image 62
Charles Duffy Avatar answered Oct 21 '22 01:10

Charles Duffy