Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker execution behavior different in command line and cmd file

I created the following script in cmd file :

docker exec my-container bash -c "stat -c '%U' /my/directory"

I have the following result :

U

But if I do the same in the command line directly, I have this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

root

If I replace U by A (to have rights instead ownership) :

docker exec my-container bash -c "stat -c '%A' /my/directory"

I have that with the command line :

drwxrwxrwx

And that with the cmd script

A

I don’t understand why. For instance, I don’t have any trouble with the following commands :

docker exec my-container bash -c "ls -al /"
docker exec my-container bash -c "su - -c 'ls -al /' myUser"

I have the expected result with the script and the command line.

>Solution :

The underlying problem is windows.
The %U is parsed in a batch file and the percent is removed, because there is no closing percent sign, else it would be replaced by the variable content like in echo %PATH%

On the command line exists different rules for the percent handling, therefore it works here.

To solve it in a batch file, just double the percent signs

docker exec my-container bash -c "stat -c '%%U' /my/directory"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading