Problem with mounting volumes


Recommended Posts

Hi.

 

Yesterday I started learning Docker for development purposes. I created simple app with Node.js server and SQLite database on backend and React on frontend.

App is creating db.sqlite file in /data directory which I wanted to mount to access the file. However when I open directory on host side, the file is not there. I've been working on it for the last 4 hours and can't figure out what I'm doing wrong.

 

Here is mu Dockerfile. Right now I'm building React app manually.

 

FROM node:14-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

RUN mkdir ./public ./data
RUN mv ./client/build/* ./public
RUN rm -rf ./client

EXPOSE 5000

CMD ["node", "server.js"]

 

I'm then starting the container with:

docker run --name app -p 5030:5000 -v /mnt/user/appdata/users:/data username/usersapp

 

When container is running and I console into it I can run ls /data and I can see the database file being there but it's not in the /mnt/user/appdata/users

 

Is there something fundamentally wrong I'm doing here?

 

Link to comment

According to your screen shots the ‘data’ folder inside the container  is not relative to the / folder inside the container but in a folder relative to a home folder, but the Docker run command IS mapping it at the host level to be relative to /.    That will be why you are seeing what you describe.

 

Link to comment
41 minutes ago, itimpi said:

According to your screen shots the ‘data’ folder inside the container  is not relative to the / folder inside the container but in a folder relative to a home folder, but the Docker run command IS mapping it at the host level to be relative to /.    That will be why you are seeing what you describe.

 

After changing it from :/data to :/app/data it’s working now. I read through all these articles and code examples and I was sure all the mappings were relative to the WORKDIR. 
 

Thanks for help

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.