Today, I would be explaining the way to maintain the DB with data persistent when connecting to docker.
System Status
Postgresql DB container is in DockerWindows 10 PC
Linux containers
Issue
Whenever I restart docker/PC the database wiped off due to container is stopped.Solution
Create a docker volume
Syntax: docker volume create <Example: docker volume create pgdata
Start the container with volume option
Syntax: docker run --rm --name <Example: docker run --rm --name pgcontainer -e POSTGRES_PASSWORD=MyPassword -d -p 5432:5432 -v pgdata:/var/lib/postgresql/data postgres
Now, you can run all your database commands
Upon restart also, your data should be safe.
Thanks for reading the blog post.
Please send your feedback and comments to psrdotcom@gmail.com
No comments:
Post a Comment