Docker client change

From Docker Desktop to Colima

Use Case:

I was using docker desktop to run mysql db and I had to move to colima as docker desktop was using too much of my battery.

Solution:

The container was not using folder from host machine rather it was internal volume where all the data was present.
The command I was using to run the container in docker desktop was:

docker run -e MYSQL_ROOT_PASSWORD='abc@123' \
-p 3306:3306 -v mysqlvolume:/var/lib/mysql --name mydb --hostname mydb \
-d mysql:lts

So, the first thing I had to was to backup the volume as all the data was present there.
The command used was:

docker run --rm -v mysqlvolume:/volume -v :/backup alpine sh -c "cp -r /volume/* /backup/"

  1. <local_destination>: This can be any path to any folder in your machine, so that the volume can be backed up here.
  2. alpine: docker will pull up the apline image from the dockerhub if not present in your machine. This is required as docker
    will spin up this image as a temporary container just to copy the existing db data to a local folder of the machine. Btw
    getting the folder from inside the container and just copy paste wont work.
  3. This command does the following:
    a) It will map the “mysqlvolume” to the alpine container’s “volume” folder
    b) It will map the to the alpine container’s “backup” folder
    c) –rm flag removes the container automatically once its work is done
    d) once the conatiner starts, it will copy all the contents from the “volume” folder to “backup” folder
    e) removes the container after the copying is done
  4. Now all the volume data is present in the

Now close the docker desktop after removing the containers. and start colima

Then, create a new volume with the following:

docker volume create

Transfer back the files from the local folder() to the newly created volume, with the following
(same as before just reverse the paths):

docker run --rm -v :/volume -v <local_destination:/backup alpine sh -c "cp -r /backup/* /volume/"

Leave a comment