Recovering MySQL Data from a Deleted Docker Container

This guide walks through locating the Docker volume of a removed MySQL container, creating a new container with the same image, and swapping the volumes to restore the original database, providing step‑by‑step commands and screenshots for successful data recovery.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Recovering MySQL Data from a Deleted Docker Container

While testing MySQL gap locks, the author discovered a forgotten MySQL container on a server and, after removing it with docker rm -f, realized the database was still actively used by a project.

Step 1: Locate the volume of the deleted container

Navigate to Docker's volume directory and list the volumes:

cd /var/lib/docker/volumes/
ll

Since the database is MySQL, search for the mysql.ibd file to identify the relevant volume: find . -name mysql.ibd Three MySQL‑related volumes appear; by checking creation times and inspecting the directory contents, the correct volume is identified.

Step 2: Launch a new container with the same image

Start a new MySQL container using the same image version:

docker run -itd -p 3306:3306 -e MYSQL_ROOT_PASSWORD=xxxxxx mysql:8.0

Step 3: Replace the new container’s volume with the recovered one

Find the new container’s volume name: docker inspect <em>new_container_name</em> Stop the new container: docker stop <em>new_container_name</em> Replace its volume with the one found in Step 1:

# go to Docker volumes directory
cd /var/lib/docker/volumes/
# delete the new container’s volume
rm -rf <em>new_container_volume_name</em>
# copy the recovered volume to the new container
cp -r <em>recovered_volume_name</em> <em>new_container_volume_name</em>

Start the container again: docker start <em>new_container_name</em> At this point the MySQL data is restored and the service is back online.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxmysqlData RecoveryVolumes
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.