Search code examples
dockercontainersdocker-volumekitematic

Docker volume restore


I had a gitlab container in docker. Today i have installed Kitematic and began to experiment. I choosed gitlab container -> Settings -> Network -> pressed 'CONNECT TO HOST NETWORK' and after that gitlab dead. After changing this setting back i have noticed that all settings are dropped now for this container. I think that container was recreated. Am i right?

I have found out some unused volumes. I'm hoping that some of these volumes contains my data which was lost after my experiments and container recreating.

How can i change volumes on existing container and how can i determine which of unused volumes was in use by previous instance of my gitlab image? And how to map them to corresponding docker folders like '/etc/gitlab', '/var/log/gitlab', '/var/opt/gitlab'? Maybe i can somehow browse them and it will help me to understand base on file structure everything?

All volumes are inside virtual machine and have no mapping to my host os drive.


Solution

  • The gitlab docker file declared three volumes:

    # Define data volumes
    VOLUME ["/etc/gitlab", "/var/opt/gitlab", "/var/log/gitlab"]
    

    Thus if you didn't name them when starting the first time, docker will automatically create volume with some random names. You can inspect each volume and see what files it actually contains:

    docker volume ls
    docker volume inspect <volume-name>
    

    Locate the Mountpoint on the host analize which volume maps to which directory in the container. You can compare that with a fresh container by

    docker exec -it <container-name> ls /var/opt/gitlab
    

    Once you figure out which volume maps to which directory, recreate the container as such:

    docker run <existing-volume1-name>:/etc/gitlab <existing-volume2-name>:/var/opt/gitlab ...