W
W
WhatYouDoing2019-03-13 10:24:45
Docker
WhatYouDoing, 2019-03-13 10:24:45

Why doesn't docker save db data to a folder on the host machine?

There is such a piece from docker-compose

db:
        hostname: postgres
        container_name: postgres
        image: postgres:10.1
        restart: always
        environment:
            - POSTGRES_DB=${DB_NAME}
            - POSTGRES_USER=${DB_USER}
            - POSTGRES_PASSWORD=${DB_PASSWORD}
        ports:
            - "5432:5432"
        volumes:
            - ./.docker/conf/postgres/:/docker-entrypoint-initdb.d/
            - ./.docker/conf/postgres/data:/var/lib/postgresql/data
        networks:
            - backend

Where it is described how the database works, and in volumes the line - ./.docker/conf/postgres/data:/var/lib/postgresql/data should save data to a folder outside the container, but this does not happen in the container itself /var/lib /postgresql/data data is present

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
WhatYouDoing, 2019-03-13
@WhatYouDoing

I had to run docker-compose up from sudo......

A
Artyom Innokentiev, 2019-03-13
@artinnok

You need to use volumes at the compose file level . Also, read about named volume .

A
Alexey Burlakov, 2020-05-04
@redflasher

Delete the db container docker-compose rm dband then run again docker-compose up.
When a new container is created (from the image cache), docker will forward the folder from the container to the host.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question