skip to Main Content

I have a docker container running cytopia/mysql-5.7, looking back (a long time ago) the command I used to create this image was

docker run -i -p 127.0.0.1:3306:3306 -e MYSQL_ROOT_PASSWORD=foobar -t cytopia/mysql-5.7

Clearly here I haven’t defined a volume or to mount anything. I want to update the engine to use mysql 8, but hopefully without losing the data that I have in the docker container. When I’ve looked into the container details with docker inspect [CONTAINER] I can see that I have the following "Mounts":

"Mounts": [
            {
                "Type": "volume",
                "Name": "2bd576f1fc716948facfe84c2bef96ab2620413789e0809a2f07bb23e6db621e",
                "Source": "/var/lib/docker/volumes/2bd576f1fc716948facfe84c2bef96ab2620413789e0809a2f07bb23e6db621e/_data",
                "Destination": "/etc/mysql/conf.d",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "5fc58add211a8bfdb4f8f89a1ca121ca1f892d05cbda47066ecf9268dcdd86a0",
                "Source": "/var/lib/docker/volumes/5fc58add211a8bfdb4f8f89a1ca121ca1f892d05cbda47066ecf9268dcdd86a0/_data",
                "Destination": "/etc/mysql/docker-default.d",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "5fcacabd273998700f467918efd2dddec756dbe8606f9a282f647a0a6c984aa1",
                "Source": "/var/lib/docker/volumes/5fcacabd273998700f467918efd2dddec756dbe8606f9a282f647a0a6c984aa1/_data",
                "Destination": "/var/lib/mysql",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "9e1b62523c7eabc2f506d809e7b08ca125ae859e9353fed8d4c7e2bb88495f94",
                "Source": "/var/lib/docker/volumes/9e1b62523c7eabc2f506d809e7b08ca125ae859e9353fed8d4c7e2bb88495f94/_data",
                "Destination": "/var/log/mysql",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "93061fa1c12ff463ba39d9bfae0a20e8d1f9b0e4aa11375a7323ca7cffee5c41",
                "Source": "/var/lib/docker/volumes/93061fa1c12ff463ba39d9bfae0a20e8d1f9b0e4aa11375a7323ca7cffee5c41/_data",
                "Destination": "/var/sock/mysqld",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],

I believe these to be anonymously created by the cytopia image (although not certain). When I docker exec to poke around the container I can’t find anything worthwhile. Using docker volume ls I can see those local volumes do exist.

I’ve tried to use docker commit based on the container to generate an image, and then create a new container based on that image. That hasn’t provided me with any luck, and simply generates another mysql-5.7 docker container with no data.

I have also tried

docker run -i -p 127.0.0.1:3306:3306 -e MYSQL_ROOT_PASSWORD=asdf -t cytopia/mysql-5.7 --name backup --volumes-from 5fcacabd273998700f467918efd2dddec756dbe8606f9a282f647a0a6c984aa1

Using the anonymous volume from the mount that corresponds to var/lib/mysql, simply to see if I can generate another 5.7 engine with the same data.

So far nothing I’ve tried has worked. Am I in a position where because I didn’t specify a volume explicitly at the start, I cannot get the database data out?

2

Answers


  1. The idea to use --volumes-from option is correct. You only need to:

    • place this option in the correct place, ie. before image name
    • use it with container name/id, not volume id
    docker run -i -p 127.0.0.1:3306:3306 -e MYSQL_ROOT_PASSWORD=asdf -t --volumes-from <container_id> cytopia/mysql-5.7
    
    Login or Signup to reply.
  2. I think at first you need to create a backup using mysqldump:

    docker exec CONTAINER_NAME mysqldump -uUSER -pPASSWORD DATABASE > backup.sql
    

    After that you can recreate a new database.

    If you can stop container you can copy all files of /var/mysql volume in another place in the filesystem and after bind it to as a volume in the new container.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search