-1

I'm trying to understand how the file structure works inside docker containers, along with understanding volumes and mounts.

One thing that's confusing me is that when I docker exec -it <container id> /bin/bash into a container, I can't cd into some directories.

For example, if I run cd logs, I'd expect to be able then run ls to get a list of log files, but I get No such file or directory following the cd logs command.

I can however run cd wwwroot and navigate around.

In the image of the terminal below, you can see the result of ls once I have exec'd in.

I can run cat logs\2019-07-04.log.json for example, to print the file contents to the screen. But I still can't do cd logs.

enter image description here

I have tried the following also:

enter image description here

It's like the file path is a 'key' rather than a proper directory structure.

So this appears to be limited to the directories that the application writes to at runtime, while the files that are loaded in on build have a proper file structure.

Is this specific to .NET Core on linux containers? Why does it work like this?

gbro3n
  • 6,729
  • 9
  • 59
  • 100
  • 1
    Wrong separator? Linux uses `/` folder separator. What you listed above is a file name, not a directory. The file name is `logs\2019-07-05.log` (read: `log\...` is part of the file name, not a directory) and **NOT** `2019-07-05.log`. Common mistake for using hardcoded `\` in pathes instead of [Path.DirectorySeparatorChar](https://learn.microsoft.com/en-us/dotnet/api/system.io.path.pathseparator?view=netcore-3.0) and [Path.Combine](https://learn.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=netcore-3.0) – Tseng Jul 05 '19 at 08:43
  • The separator is as it is because this is a .NET Core app. Looks like I have some work to do on paths. I'd assumed there was some sort of translation between path separator chars when running .NET core on linux but possibly not. https://stackoverflow.com/questions/38168391/cross-platform-file-name-handling-in-net-core – gbro3n Jul 05 '19 at 09:51
  • 1
    I doubt that. The `Path.DirectorySeparatorChar` will be different depending on which OS you are. You **are** hardcoding it somewhere, that's why you see it. When you use the regular File/Directory APIs its properly read as well as if you do `Path.Combine("logs", fileName)`, because `Path.Combine` will use the OS specific directory separator – Tseng Jul 05 '19 at 09:55
  • Yes, I know that it is card coded in places, and the logging specifically is coming from NLog config, which I can change in the production environment. Thank you for your comments, most helpful. – gbro3n Jul 05 '19 at 10:00
  • File an issue on the [NLog issue tracker](https://github.com/NLog/NLog/issues) ? – Tseng Jul 05 '19 at 10:44

1 Answers1

1

That is because there's no folder called logs, you created to files called logs\2019-07-04.log.json and logs\2019-07-05.log.json in order to fix this:

First create a new folder mkdir logs

Then move the files to the folder mv logs\\2019* logs/

The double \\ will be necessary in order to use only one \. Then you should be able to ls.

Regards ;)

W4nn4Die
  • 11
  • 3
  • I think I do need to create a directory, but Tseng's comments are probably the answer here. Thank you. – gbro3n Jul 05 '19 at 10:02