• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
Sunday, January 11, 2026
newsaiworld
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
Morning News
No Result
View All Result
Home Data Science

How To Use Docker Volumes for Persistent Knowledge Storage

Admin by Admin
August 26, 2024
in Data Science
0
Serene Cottage Setting View Out The Lake From Dock.png
0
SHARES
3
VIEWS
Share on FacebookShare on Twitter


How To Use Docker Volumes for Persistent Data StorageHow To Use Docker Volumes for Persistent Data Storage

 

When utilizing Docker, you should utilize volumes to persist knowledge even whenever you cease or restart the containers. We’ll create and use Docker volumes for PostgreSQL.

Stipulations

 

To comply with together with this tutorial:

  • You must have Docker put in in your machine
  • You ought to be comfy with Docker instructions and PostgreSQL

 

Step 1: Pull the PostgreSQL Picture

 

First, we pull the PostgreSQL picture from DockerHub:

 

Step 2: Create a Docker Quantity

 

Subsequent, let’s create a Docker quantity to retailer the information. This quantity will persist the information even when the container is eliminated.

$ docker quantity create pg_data

 

Step 3: Run the PostgreSQL Container

 

Now that we’ve pulled the picture and created a quantity, we are able to run the PostgreSQL container attaching the created quantity to it.

$ docker run -d 
	--name my_postgres 
	-e POSTGRES_PASSWORD=mysecretpassword 
	-v pg_data:/var/lib/postgresql/knowledge 
	-p 5432:5432 
	postgres

 

This command runs my_postgres in indifferent mode. Utilizing –v pg_data:/var/lib/postgresql/knowledge mounts the pg_data quantity to /var/lib/postgresql/knowledge within the container. And utilizing -p 5432:5432 maps port 5432 of my_postgres to port 5432 on the host machine.

 

Step 4: Confirm the Quantity Utilization

 

Now that we’ve created the amount, we are able to confirm it’s getting used. You possibly can examine the amount and verify the contents.

$ docker quantity examine pgdata

 

Operating this command will present particulars in regards to the quantity, together with its mount level in your host system. You possibly can navigate to this listing and see the PostgreSQL knowledge recordsdata.

[
	{
    	"CreatedAt": "2024-08-07T15:53:23+05:30",
    	"Driver": "local",
    	"Labels": null,
    	"Mountpoint": "/var/lib/docker/volumes/pg_data/_data",
    	"Name": "pg_data",
    	"Options": null,
    	"Scope": "local"
	}
]

 

Step 5: Create a Database and Desk

 

Hook up with the Postgres occasion and create a database and desk.

Begin a psql session:

$ docker exec -it my_postgres psql -U postgres

 

Create a brand new database:

 

Hook up with the brand new database:

 

Create a desk and insert some knowledge:

CREATE TABLE customers (
    id SERIAL PRIMARY KEY,
    identify VARCHAR(100),
    e mail VARCHAR(100)
);

INSERT INTO customers (identify, e mail) VALUES ('Abby', 'abby@instance.com'), ('Bob', 'bob@instance.com');

 

Run a pattern question:

 

Output:

 id | identify |  	e mail  	 
----+------+------------------
  1 | Abby | abby@instance.com
  2 | Bob  | bob@instance.com

 

Step 6: Cease and Take away the Container

 

Cease the operating container and take away it. We do that so we are able to take a look at that the information persists even when the container is stopped.

$ docker cease my_postgres
$ docker rm my_postgres

 

 

Step 7: Re-run the Postgres Container with the Similar Quantity

 

Begin a brand new PostgreSQL container with the identical quantity to make sure knowledge persistence.

$ docker run -d 
	--name my_postgres 
	-e POSTGRES_PASSWORD=mysecretpassword 
	-v pgdata:/var/lib/postgresql/knowledge 
	-p 5432:5432 
	postgres

 

Hook up with the Postgres occasion and confirm that the information persists.

Open a psql session:

$ docker exec -it my_postgres psql -U postgres

 

Hook up with the mydb database:

 

Confirm the information within the customers desk:

 

You must nonetheless see the output:

 id | identify |  	e mail  	 
----+------+------------------
  1 | Abby | abby@instance.com
  2 | Bob  | bob@instance.com

 

I hope this tutorial helps you perceive how one can use volumes to persists knowledge when working with Docker.

 

Further Sources

 

To study extra, learn the next sources:

Completely satisfied exploring!

 
 

Bala Priya C is a developer and technical author from India. She likes working on the intersection of math, programming, knowledge science, and content material creation. Her areas of curiosity and experience embrace DevOps, knowledge science, and pure language processing. She enjoys studying, writing, coding, and occasional! Presently, she’s engaged on studying and sharing her information with the developer group by authoring tutorials, how-to guides, opinion items, and extra. Bala additionally creates partaking useful resource overviews and coding tutorials.



READ ALSO

Highly effective Native AI Automations with n8n, MCP and Ollama

Function of QR Codes in Knowledge-Pushed Advertising

Tags: DataDockerPersistentStoragevolumes

Related Posts

Kdn powerful local ai automations n8n mcp ollama.png
Data Science

Highly effective Native AI Automations with n8n, MCP and Ollama

January 10, 2026
Image fx 20.jpg
Data Science

Function of QR Codes in Knowledge-Pushed Advertising

January 10, 2026
Kdn 5 useful python scripts automate data cleaning.png
Data Science

5 Helpful Python Scripts to Automate Knowledge Cleansing

January 9, 2026
Image fx 21.jpg
Data Science

How Information Analytics Helps Smarter Inventory Buying and selling Methods

January 9, 2026
Generic ai shutterstock 2 1 2198551419.jpg
Data Science

AI Will Not Ship Enterprise Worth Till We Let It Act

January 8, 2026
Kdn vibe coding what you can actually build.png
Data Science

Vibe Code Actuality Verify: What You Can Really Construct with Solely AI

January 8, 2026
Next Post
Bitget Id D10c4574 4163 47ea 8dc4 4df884ea0118 Size900.jpg

Bitget Joins Forces with KoinX to Simplify Crypto Tax Reporting

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

Chainlink Link And Cardano Ada Dominate The Crypto Coin Development Chart.jpg

Chainlink’s Run to $20 Beneficial properties Steam Amid LINK Taking the Helm because the High Creating DeFi Challenge ⋆ ZyCrypto

May 17, 2025
Image 100 1024x683.png

Easy methods to Use LLMs for Highly effective Computerized Evaluations

August 13, 2025
Gemini 2.0 Fash Vs Gpt 4o.webp.webp

Gemini 2.0 Flash vs GPT 4o: Which is Higher?

January 19, 2025
Blog.png

XMN is accessible for buying and selling!

October 10, 2025
0 3.png

College endowments be a part of crypto rush, boosting meme cash like Meme Index

February 10, 2025

EDITOR'S PICK

Shutterstock Robot Freedom.jpg

The way to exploit high LRMs that reveal their reasoning steps • The Register

February 25, 2025
Asic id 60491bfa 76dd 443b 8ee7 851bbacd8cbe size900.jpg

ASIC Confirms Stablecoins and Tokenised Property Fall Beneath Monetary Regulation

October 29, 2025
Langgraph And Genai.png

LangGraph Orchestrator Brokers: Streamlining AI Workflow Automation

May 15, 2025
17slerbx3bxmwkhbxm 2 Mq.gif

Getting Began with Highly effective Knowledge Tables in Your Python Internet Apps | by Tom Gotsman | Oct, 2024

October 6, 2024

About Us

Welcome to News AI World, your go-to source for the latest in artificial intelligence news and developments. Our mission is to deliver comprehensive and insightful coverage of the rapidly evolving AI landscape, keeping you informed about breakthroughs, trends, and the transformative impact of AI technologies across industries.

Categories

  • Artificial Intelligence
  • ChatGPT
  • Crypto Coins
  • Data Science
  • Machine Learning

Recent Posts

  • Bitcoin Community Mining Problem Falls in Jan 2026
  • Past the Flat Desk: Constructing an Enterprise-Grade Monetary Mannequin in Energy BI
  • Federated Studying, Half 1: The Fundamentals of Coaching Fashions The place the Information Lives
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy

© 2024 Newsaiworld.com. All rights reserved.

No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us

© 2024 Newsaiworld.com. All rights reserved.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?