node.jsdockernginxmeteormup

How to access the file written on docker container volumes and share the URL to client side using NGINX


I am new to using Docker. I have installed MUP (meteor-up) for deploying my meteor application. And that internally using the Docker.

Before using the MUP(Docker):-

I simply write few of my files(CSV) to the /opt/AHD directory in my Ubuntu machine. And with the help of NGINX, I just send the URL to client-side and auto download that file.

The configuration of my NGINX was:-

server {
    listen 7004;
    listen [::]:7004;

    server_name _;

    root /;
    #index index.html;

    location /opt {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # Following is necessary for Websocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    autoindex on;
    }

And I just share the URL of the file from my server side to client side i.e something like:-

http://myapp:7004/opt/AHD/1536673499271.csv

That was run perfectly, but as I use MUP that internally using Docker. So now as I go through and found that there is not any file written on my machine /opt/AHD directory. Because they are written in Container scope i.e they written in

var/lib/docker/overlay2/e4cc915015ea4f1e177175b52675f67223235c909b7680dfbe9a566af303afe7/diff/opt/AHD/1536673499271.csv

the above directory that is fine according to docker.

But as I want to share the URL to client side so that the CSV file downloaded at the client side.

So my question is:-

How can I config my Nginx so that it will work with the container directory instead fo my machine directory and I will be able to download the file at client side via NGINX.

I have already go through with few blogs but didn't get to know how and what configuration I need to give my nginx for accessing the docker container files.

Any help is much appreciated.

Thanks


Solution

  • Did you try mounting your /opt/AHD directory with the /opt/AHD directory inside the container?

    Please take a look at this page: http://meteor-up.com/docs.html

    In the sample configuration here, look at the volumes section

    // lets you add docker volumes (optional). Can be used to
    // store files between app deploys and restarts.
    volumes: {
      // passed as '-v /host/path:/container/path' to the docker run command
      '/host/path': '/container/path',
      '/second/host/path': '/second/container/path'
    },
    

    you can use this. Just add another line

    '/opt/AHD/': '/opt/AHD'
    

    This would mount a specific directory on your machine to a specific directory on the container. This would result in the container writing the files to your machine's directory from where you can use NGINX to move ahead.