Alright so I have a node app that access a directory in it's file structure and does stuff with it. I'm using the 'fs' module to accomplish this. When I run a container from its image, I get the following error:

```
Error: ENOENT, readdir './classes/cs395'

```

I immediately thought of a whole bunch of things that could be wrong UNTIL I attached to the running container (after restarting it because the container will die upon error...of course). When I started the node app from inside the container..it worked..no errors. 

I believe it might have something to do with the way file systems are handled when docker images are layered but when it worked fine when I attached to the container I became really confused

EDIT:

The file DOES exists...here's proof:
[![enter image description here](https://i.stack.imgur.com/czViA.png)](https://i.stack.imgur.com/czViA.png)
Again, if (as i'm attached to the container as shown in the picture) I run `node server.js` and ping the ip:port everything works great! the directory is recognized! But NOT if is run detached from the image.

To show that the file is still there, let's start our stopped container and attach to it...as you can see the file is still there. (Note that starting the container won't recreate the file it wasn't there when it stopped...it will just pick up where it left off)
[![enter image description here](https://i.stack.imgur.com/hxgWG.png)](https://i.stack.imgur.com/hxgWG.png)

In case it helps, here is how I am using the 'fs' module:

```
var p = "./classes/cs395";

//READ ALL FILES FROM A DIRECTORY AND EMIT THE NAME OF THE FILE
fs.readdir(p, function(err, files){
    if (err) throw err;

    files.forEach(function (file) {
        if (files.length == 1 && file == '.DS_Store'){
            io.emit('receive_file', null);
        } else {
            fs.stat(p + '/' + file, function(err, stats){
                if (err) throw err;

                if (stats.isFile() && file != '.DS_Store'){
                    var ext = path.extname(file);
                    var name = path.basename(p + '/' + file, ext);
                    io.emit('receive_file', name);
                }
            });

        }
    });  

    if (files.length == 0) {
        io.emit('receive_file', null);
    }    

    console.log(files);
}); 

```