Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

427
Views
How to add volume mount to running postgreSQL container?

I have a running postgreSQL docker container and need to add a volume mount.

I followed the steps from How can I add a volume to an existing Docker container?, (ran docker commit on the container to save it as an image, and spun up another container based on that image with a named volume mounted in). All the data files from the first container are present in /var/lib/postgres/data of the second container.

However, when I try to query this second postgres database, I cannot see any tables that are in the first container. Been trying to fix this for a few days with no luck, am I missing something here (does mounting a volume obscure the existing data in /var/lib/postres/data)?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Commit will not work as there is the volume defined in the Dockerfile.

Volumes are useful in many cases, for example, for running database-storage. However, since volumes are not 'part' of a container, it makes containers no longer portable - which seems in direct conflict with the slogan "Build once... Run anywhere.."

docker commit data container with VOLUME

One option that you can try is copying data folder to host from an existing container and then launch the container with mount path.

docker cp my_db_cotainer:/var/lib/postgresql/data  db_data

then start a new container with this path so it will contain the same data as the previous one

docker run -d --name some-postgres -v $PWD/db_data/:/var/lib/postgresql/data postgres

same for mysql

docker cp some-mysql-old:/var/lib/mysql db_backup
docker run --rm --name some-mysql-new -v $PWD/db_backup:/var/lib/mysql  -it mysql
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!