5

I have (had) a data container which has a volume used by other containers (--volumes-from).

The data container has accidentally been removed.

Thankfully the volume was not removed.

Is there any way I can re run the data container and point it BACK to this volume?

3 Answers 3

3

Is there any way can re run the data container and point it BACK to this volume?

Sure, I detailed it in "How to recover data from a deleted Docker container? How to reconnect it to the data?"

You need to create a new container with the same VOLUME (but its path /var/lib/docker/volumes/... would be empty or with an initial content)

Then you move your legacy volume to the path of the volume of the new container.

More generally, whenever I start a data volume container, I register its volume path in a file (to reuse that path later if my container is accidentally removed)

1
  • You are a star, sounds like the perfect solution. My only issue now is to try to work out which of the 50 volumes on that machine is the one that i need!! Once that is done Ill use your approach for keeping track of the volume in use. Cheers, m Jan 14, 2016 at 13:44
1

Not entirely sure but you might try

docker run -i -t --volumes-from yourvolume ubuntu /bin/bash

You should then be able to access the directory, i think.

4
  • 1
    As long as you've still got "yourvolume" i believe launching any other container with --volumes-from should re-connect.
    – Emile
    Jan 13, 2016 at 17:55
  • 1
    I still have the volume, but not the container that created it. and the value of --volumes-from is the container name, which no longer exists... Jan 13, 2016 at 18:05
  • Afraid i have little expertise, only just managed to grasp volumes myself. I'm not quite sure what you mean by you still have the volume. Posting your docker ps -a output may help someone else determine what you can do.
    – Emile
    Jan 13, 2016 at 18:24
  • When you create, build and run a docker container with en external volume (data written to the host), you end up with an 'image', 'container' and 'volume'. I have deleted the 'image' and 'container' but the 'volume' is still there. The issue is, once the 'container' that linked to the 'volume' has gone, I cant see how to get back to the 'volume' Jan 14, 2016 at 10:24
1

When I came to this question, my main concern was data loss. Here is how I copied data from a volume to AWS S3:

# Create a dummy container - I like Python
host$ docker run -it -v my_volume:/datavolume1 python:3.7-slim bash

# Prepare AWS stuff
# executing 'cat ~/.aws/credentials' on your development machine
# will likely show them
python:3.7-slim$ pip install awscli
python:3.7-slim$ export AWS_ACCESS_KEY_ID=yourkeyid
python:3.7-slim$ export AWS_SECRET_ACCESS_KEY=yoursecrectaccesskey

# Copy
python:3.7-slim$ aws s3 cp /datavolume1/thefile.zip s3://bucket/key/thefile.zip

Alternatively you can use aws s3 sync.

MySQL / MariaDB

My specific example was about MySQL / MariaDB. If you want to backup a database of MySQL / MariaDB, just execute

$ mysqldump -u [username] -p [database_name] \
            --single-transaction --quick --lock-tables=false \
            > db1-backup-$(date +%F).sql

You might also want to consider

  • --skip-add-drop-table: Skip the table creation if it already exists. Without this flag, the table is dropped.
  • --complete-insert: Add the column names. Without this flag, there might be a column mismatch.

To restore the backup:

$ mysql -u [username] -p [database_name] < [filename].sql

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.