Yury Kerbitskov
Yury Kerbitskov

Reputation: 663

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.

Upvotes: 0

Views: 713

Answers (2)

yamenk
yamenk

Reputation: 51768

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 ...

Upvotes: 1

Alfonso Tienda
Alfonso Tienda

Reputation: 3689

Seems to be recreated, yes. If you've run run instead of start this is the behaviour, but I'm not sure.

Volumes (one example):

docker run -v your-vm-path:/var/opt/gitlab gitlab:latest

Your data should be in your old volumes (local vm path). If not, you were not using those volumes.

If the data is in your local-vm paths (vols), see docker cp --help to put your data in your container or to get the data from your container.

For docker, your host is your virtual machine.

Upvotes: 1

Related Questions