How to write into host mounted folder from docker container

Alex Jolig :

I have a small project running as a docker container to backup my MongoDB data. the backup data is suppose to save in docker host machine. So I'm using volume in the docker-compose file:

version: '3'

services:
  mongo_backup:
    container_name: mongo_backup
    build: .
    command: python3 app.py
    volumes:
      - ./backups:/backups

When I run this code, a folder named backups gets created in the project folder in host machine.

if not os.path.exists('./backups/'):
    os.mkdir('./backups/')

But when I try to create another folder inside the ./backups/ folder, nothing happens with no errors.

if not os.path.exists('./backups/another-folder'):
    os.mkdir('./backups/another-folder')

The second folder gets created inside the docker container but nothing happens inside the host machine.

I've set the full access for the entire project folder in case the problem is related to write permissions:

sudo chmod -R 777 address/to/project/

But it didn't help.

I need to create different folders in the first folder, so I can't add them all as volumes. I know I'm missing something. I just don't know what!

This is my Dockerfile just in case:

FROM python:3.6

WORKDIR /app

COPY src/requirements.txt /app
RUN pip3 install -r /app/requirements.txt
COPY ./src /app
kederrac :

you have to map your volumes like this:

- ./backups:/app/backups

because your working directory is /app

here ./backups/another-folder you are using relative path but you are inside of /app so your full path will be /app/backups/another-folder

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=404857&siteId=1