Hello to all the readers!

Any data that is generated inside a container by operations is lost once container is stopped. Therefore in order to persist the data in a container, volumes are created and attached to the container.

docker volume create todo-db                                                                                                                                                          
todo-db

docker volume list
DRIVER    VOLUME NAME
local     todo-db

Now we will run a container created out of getting-started image and mount the volume to persist the data.

docker run -dp 3000:3000 --mount type=volume,src=todo-db,target=/etc/todos getting-started

Now open localhost:3000 and add todo items. Then stop and remove container and again run it with above command.

We will find that the todo items are shown because they were stored in persistent volume.

To see where volume is exactly stored on the filesystem, then here to check.

docker volume inspect todo-db                                                                                                                                                         

[
    {
        "CreatedAt": "2023-06-22T11:05:10+05:30",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/todo-db/_data",
        "Name": "todo-db",
        "Options": null,
        "Scope": "local"
    }
]

Similar Posts

Error: GraphComment couldn't be load because your settings are invalid. Please visit your admin panel and go to the GraphComment section and enter a valid website URL/ID.